macos 双击运行applescript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2543650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
run applescript on 2x-click
提问by scottru
OK, this feels like an idiot question, but I'm stuck - I don't know the first thing about AppleScript. I have a .scpt file and I want to double-click it and just have it run, but instead every time I click, it opens up the AppleScript Editor. This feels like it should just be an option on the file, but I'm missing something obvious.
好的,这感觉像是一个白痴问题,但我被卡住了 - 我不知道关于 AppleScript 的第一件事。我有一个 .scpt 文件,我想双击它并让它运行,但每次单击时,它都会打开 AppleScript 编辑器。这感觉就像它应该只是文件中的一个选项,但我遗漏了一些明显的东西。
Please help me feel less dumb, thank you.
请帮助我感觉不那么愚蠢,谢谢。
回答by Antal Spector-Zabusky
From the “File” menu, choose “Export”; there'll be a “File Format” dropdown underneath the file browser. To get a double-clickable application instead of a document, choose “Application”. This will produce a .app
bundle like ordinary Mac applications (this will also let you package other resources with your script if you need to). You can choose “Run Only” or not; if you do, then anybody with just the .app
won't be able to edit your script further, since it'll be compiled. (But if you're saving a copy as the application, that might be what you want.)
从“文件”菜单中,选择“导出”;文件浏览器下方会有一个“文件格式”下拉菜单。要获得可双击的应用程序而不是文档,请选择“应用程序”。这将生成一个.app
像普通 Mac 应用程序一样的包(如果需要,这也可以让您用脚本打包其他资源)。您可以选择“仅运行”或“不运行”;如果你这样做了,那么任何人.app
都不能进一步编辑你的脚本,因为它会被编译。(但如果您将副本另存为应用程序,那可能就是您想要的。)
Another option, as per an anonymous user on Ask Different, would be to save/export your file as a “Script” (.scpt
) or “Script Bundle” (.scptd
), save it in ~/Library/Scripts/
, and check “Show Script menu in menu bar” in Script Editor's preferences.
根据 Ask Different 上的匿名用户的说法,另一种选择是将您的文件保存/导出为“脚本”( .scpt
) 或“脚本包”( .scptd
),将其保存在 中~/Library/Scripts/
,然后选中“在菜单栏中显示脚本菜单”脚本编辑器的首选项。
(If you're running an old version of OS X, the first version of this answerhas the information you're looking for.)
(如果您运行的是旧版本的 OS X,则此答案的第一个版本包含您要查找的信息。)
回答by doug
There's more than one way to do it; i have found this to be the simplest:
有不止一种方法可以做到;我发现这是最简单的:
In sum, you create an Automatorapplication and place your applescript inside it (easier than it sounds, and it's not a hack either--there's actually a specific Automator action for this). Then when you are finished, you select "File" from the menubar, next "Save As Application", then select a location. Now check there and you'll see the newly-created Automator icon (little white robot holding a grenade launcher).
总而言之,您创建了一个Automator应用程序并将您的 applescript 放入其中(比听起来容易,而且它也不是一个黑客——实际上有一个特定的 Automator 操作)。完成后,从菜单栏中选择“文件”,然后选择“另存为应用程序”,然后选择一个位置。现在检查那里,您将看到新创建的 Automator 图标(拿着榴弹发射器的白色小机器人)。
You can do anything that you would ordinarily do with this application icon--double click to open, drag it to your dock, etc.
您可以使用此应用程序图标执行您通常会执行的任何操作——双击打开,将其拖至 Dock 等。
Appstorm has created an excellent step-by-step tutorialfor building an applescript-embedded automator action. On the page i linked to, the tutorial author has also supplied an Automator script that you can download and use as a template.
Appstorm 创建了一个优秀的分步教程,用于构建嵌入 AppleScript 的自动操作。在我链接到的页面上,教程作者还提供了一个 Automator 脚本,您可以下载并用作模板。
回答by esmail
While it's certainly not the simplest route, one benefit to running your script from Automator, as doug suggested, is that you can set a hotkey or keyboard shortcut to execute your script if you hide it in an Automator Service (OSX 10.6+). See:
虽然这肯定不是最简单的方法,但正如 doug 所建议的那样,从 Automator 运行脚本的一个好处是,如果将脚本隐藏在 Automator 服务 (OSX 10.6+) 中,则可以设置热键或键盘快捷键来执行脚本。看:
http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/
http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/
回答by Kayjek
When you save a new script, a menu should appear asking what you want the file name to be, where it will be stored, any tags for it, and what script format you want it to be. There should be 4 scripts formats:
当您保存一个新脚本时,应该会出现一个菜单,询问您想要的文件名、存储位置、任何标签以及您想要的脚本格式。应该有 4 种脚本格式:
- Script
- Script Bundle
- Application
- Text
- 脚本
- 脚本包
- 应用
- 文本
The script format you want to use would be "Application." This will turn it into a double-click application if its not in the dock.
您要使用的脚本格式是“应用程序”。如果它不在 Dock 中,这将把它变成一个双击应用程序。