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

124 天前
 klgd

刚入手的 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
731 次点击
所在节点    Apple
2 条回复
ihwbunny
124 天前
只看了第一个,你把“ with properties {name:"Open Chromium with Custom Data Dir.app"}”删了,就变清澈了。但是其实还是运行不成功。

shell 最简单, 比如下面,以后只要是把 localProfile 变量改一下,另存为一个新的脚本或者.command 文件。
如果稍微复杂点,用 shell 创建多个 open chromium 的脚本也是很容易,比如就是一个循环 for i in {1..10} 就可以帮你创建 10 个可运行脚本
用 AppleScript 创建,其实是一样的,不过它的语法更啰嗦。你上面的两个都没有涉及到创建多个的问题。

#!/bin/bash
localProfile="/Users/admin/Library/Chromium/Data/1"
mkdir -p "$localProfile"
/Applications/Chromium.app/Contents/MacOS/Chromium --user-data-dir="$localProfile"
klgd
123 天前
@ihwbunny #1 是的 shell 是最简单的了,只是看到 applescript 这个东西了,就想多了解了解

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1043158

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX