“将这个applescript组合成一行的最佳方法是什么?”
使用 AppleScript?:-D
首先,在 AppleScript Editor 中,打开 Preferences 窗口并单击选项以Show Script menu in menu bar
.
然后Open Scripts Folder
从屏幕右上角的脚本菜单项中选择。
使用以下脚本创建一个新的 AppleScript .scptd 文档:
tell application "AppleScript Editor"
set string_ to text of first document
-- make a list with each line of the script
set stringLines to paragraphs of string_
set originalDelims to AppleScript's text item delimiters
-- add newlines
set AppleScript's text item delimiters to "\\n"
-- now combine the items in the list using newlines
set stringNewlines to stringLines as string
set AppleScript's text item delimiters to "\""
set stringNewlines to text items of stringNewlines
set AppleScript's text item delimiters to "\\\""
set stringNewlines to stringNewlines as string
set AppleScript's text item delimiters to originalDelims
set stringNewlines to "@\"" & stringNewlines & "\""
set the clipboard to stringNewlines
end tell
(请注意,此脚本并不完美:它适用于您提供的简单脚本,但无法自行转换)。
将其保存为您之前显示的 Scripts 文件夹中的脚本。
然后打开您要转换的脚本文档,并将其设置为 AppleScript 编辑器中的前端文档。然后通过从脚本菜单中选择来调用转换脚本。
鉴于您提供的脚本,它应该产生以下常量NSString
:
@"tell application \"Terminal\"\n activate\n set currentTab to do script \"1\"\n do script \"2\" in currentTab\n do script \"3\" in currentTab\n do script \"4\" in currentTab\n delay 0.5\n tell application \"Finder\" to set visible of process \"Terminal\" to false\nend tell\n"