将 Applescript 更改为单行 NSApplescript 源
我正在构建一个应用程序,用于学习使用 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 组合成一行的最佳方法是什么?谢谢!
Im building an app for learning purposes of using applescript to send multiple commands during an action. Below is the code I'm messing with but I have stripped out the actions in between the "" and replaced them with numbers. Everything works fine in applescript but making this into an NSApplescript initwithsource: line has been a bother.
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
What is the best way to combine this applescript into a single line? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用AppleScript? :-D
首先,在 AppleScript 编辑器中,打开“首选项”窗口,然后单击“在菜单栏中显示脚本菜单”选项。
然后从屏幕右上角的脚本菜单项中选择
打开脚本文件夹
。使用以下脚本创建一个新的 AppleScript .scptd 文档:(
请注意,此脚本并不完美:它对于像您提供的脚本这样的简单脚本运行良好,但无法自行转换)。
将其另存为您之前显示的 Scripts 文件夹中的脚本。
然后打开要转换的脚本文档,并将其设为 AppleScript 编辑器中的前端文档。然后从“脚本”菜单中选择转换脚本来调用它。
根据您提供的脚本,它应该生成以下常量
NSString
:Use AppleScript? :-D
First, in AppleScript Editor, open the Preferences window and click the option to
Show Script menu in menu bar
.Then choose
Open Scripts Folder
from the script menu item up in the upper right of the screen.Create a new AppleScript .scptd document with the following script:
(Note that this script isn't perfect: it works fine for simple scripts like the one you provided, but isn't able to convert itself).
Save that as a script in the Scripts folder you revealed earlier.
Then open your script document you want to convert and make it the front document in AppleScript Editor. Then invoke the conversion script by choosing it from the Script menu.
Given the script you provided, it should produce the following constant
NSString
: