请教, AppleScript 脚本,实现创建 Automator 应用

21次阅读

共计 1400 个字符,预计需要花费 4 分钟才能阅读完成。

刚入手的 mac,纯小白

先说目的:需要用 chrome 多开
搜索一番,可以用 shell 脚本 open chrome,也可以用 Automator 创建一个 run shell 应用(有点儿像 win 里的快捷方式?)
shell 脚本作为最后的选择,想先试着学学 Automator,因为要创建多个,又太想一个一个手动去 Automator 创建,搜索后了解 可以用 AppleScript 来实现批量创建,但是 gpt 给的脚本有误,请教大家,这个 AppleScript 脚本该如何实现

以下 2 个 script 执行都会报语法错误:
预期是行的结尾等等,却找到“{”。
预期是行的结尾等等,却找到标识符。

set appPath to (path to desktop as text) & "OpenChromiumWithDataDir.app"
set chromiumPath to "/Applications/Chromium.app/Contents/MacOS/Chromium"
set userDataDir to "/Users/admin/Library/Chromium/Data/1"
set shellScript to chromiumPath & "--user-data-dir=" & userDataDir

tell application "Automator"
    activate
    set newApp to make new document
    set type of newApp to application
    set name of newApp to "Open Chromium with Custom Data Dir"
    tell newApp
        set newAction to make new "Run Shell Script" at end of actions with properties {name:"Run Shell Script", script:shellScript}
    end tell
    save newApp in appPath with properties {name:"Open Chromium with Custom Data Dir.app"}
end tell
tell application "Automator"
    set newWorkflow to make new workflow with properties {name:"Launch Chromium with Profile 1"}
    delay 1
    set newLibrary to expose library of newWorkflow
    set newShell to make new action of class "Run Shell Script" with properties {name:"Launch Chromium with Profile 1"}
    set contents of newShell to "/Applications/Chromium.app/Contents/MacOS/Chromium --user-data-dir=/Users/admin/Library/Chromium/Data/1"
    tell newLibrary to add action newShell after action 0
    set newApplication to (path to desktop as text) & "Launch Chromium with Profile 1.app"
    save newWorkflow in file newApplication
end tell
正文完
 0