【问题标题】:Workflow stopped working after changing to MacBook Pro M1换成 MacBook Pro M1 后工作流程停止工作
【发布时间】:2021-01-31 20:32:24
【问题描述】:

当我升级到 MacBook Pro M1 时,我遇到了一个工作流程停止工作的问题。 此工作流程用作 Finder 文件中的快速操作。首先,我尝试直接从 Automator 运行,令我惊讶的是它可以工作,然后再次尝试作为快速操作但不起作用。我已经在互联网上搜索了一个多月并尝试了不同的方法,但无法通过 Quick Action 使其再次起作用。

为了便于解释,我只提取了有问题的代码。目的是获取电影文件的大小。以下代码可在 Automator 中运行,但从快速操作运行时会出现错误:找不到文件。

    tell application "Finder"
        set existingMovies to (every file of theFolder) as alias list
    end tell
    
    repeat with movie in existingMovies
        --repeat with movie in input
        set theMovie to the (quoted form of POSIX path of movie) as string
        set movieSize to do shell script "/usr/bin/mdls -name kMDItemDurationSeconds -raw -nullMarker 0 " & theMovie
    end repeat

然后我尝试使用工作流的输入参数(在本例中为文件列表,因为此工作流使用“工作流接收当前:电影文件”)。使用这种方法,它既适用于 Automator,也适用于 Finder Action

    repeat with movie in input
        set theMovie to the (quoted form of POSIX path of movie) as string
        set movieSize to do shell script "/usr/bin/mdls -name kMDItemDurationSeconds -raw -nullMarker 0 " & theMovie
    end repeat

在所有情况下,我都使用同一个文件夹。 输入指定的文件列表似乎与我从指定文件夹(existingMovies)创建的文件列表有所不同。

知道为什么会这样吗?

【问题讨论】:

    标签: applescript


    【解决方案1】:

    我无法在我的机器上复制您的问题,所以我不能确定出了什么问题。但这是对脚本的“最佳实践”改造。看看能不能解决你的问题。

    on run {input, parameters}
        -- always use System Events, not the Finder, where possible
        tell application "System Events"
            repeat with thisFolder in input
                set existingMovies to (every file of thisFolder)
                repeat with movie in existingMovies
                    -- dereference properties with 'get' 
                    set theMovie to the (quoted form of (get POSIX path of movie))
                    set movieSize to do shell script "/usr/bin/mdls -name kMDItemDurationSeconds -raw -nullMarker 0 " & theMovie
                end repeat
            end repeat
        end tell
        return input
    end run
    

    【讨论】:

    • 不知何故代码在旧机器上工作。非常感谢您的建议,它现在可以在 Automator 和快速操作中使用
    猜你喜欢
    • 2021-05-08
    • 2021-07-19
    • 1970-01-01
    • 2023-03-26
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多