我正在构建一个学习使用applescript在一个动作中发送多个命令的应用程序。下面是我正在处理的代码,但我已经去掉了"“之间的动作,并将它们替换为数字。在applescript中一切都很好,但是将这段代码放入NSApplescript initwithsource:行中是一件麻烦的事情。
tell application "Terminal"
activate
set currentTab to do script "1"
do script "2" in currentTab
do script "3" in currentTab
do script "4" in currentTab
delay 0.5
tell application "Finder" to set visible of process "Terminal" to false
end tell将此applescript合并为一行的最佳方法是什么?谢谢!
发布于 2011-09-26 10:40:26
“将此应用程序脚本合并为一行的最佳方法是什么?”
使用AppleScript?:-D
首先,在AppleScript编辑器中,打开Preferences窗口,然后单击Show Script menu in menu bar选项。
然后从屏幕右上角的script菜单项中选择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编辑器中打开要转换的脚本文档并将其设置为前端文档。然后通过从script菜单中选择它来调用转换脚本。
给定您提供的脚本,它应该生成以下常量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"https://stackoverflow.com/questions/7549667
复制相似问题