在扩展坞上时使用 AppleScript 为应用程序添加自定义菜单项
您可以编写 AppleScript 并将其另存为应用程序,然后将其放置在 Dock 上。但是是否可以向其中添加菜单项,以便在二次单击时显示这些菜单项?如果是这样,如何定义它们并定义它们的行为?
谢谢
You can write an AppleScript and save it as an application, and then place it on the dock. But is it possible to add menu items to it so that when secondary clicked it show these menu items? If so, how to define them, and define their actions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我挖出了我是怎么做到的。这适用于 leopard 和更旧的版本:它是 shell 命令的可可应用程序包装器。对于雪豹,您可以直接为苹果脚本执行此操作。
现在,右键单击时,dock 中的程序应该有“file->runHello”项目。
您可以删除“Mainmenu.xib”中的窗口。 NSTask 还可以执行所有 shell 命令,而不仅仅是脚本。
Snow Leopard 中有一个“applescript IBAction”。您可以将“Cocoa 应用程序”更改为“Applescript 应用程序”。
br,
尤哈
I dug out how I did it. This works for leopard and older: It's a cocoa app wrapper for shell commands. For snow leopard you can do it directly for apple scripts.
Now the program in dock should have "file->runHello" item when right clicked.
You can delete the window in "Mainmenu.xib". Also NSTask can excecute all shell commands, not just scripts.
In Snow Leopard there is an "applescript IBAction". And you can change "Cocoa Application" to "Applescript application".
br,
Juha
Applescript 无法做到这一点。将 Applescript 保存为应用程序实际上只消除了需要脚本编辑器来运行脚本的要求以及其他一些小的更改。说到底,它仍然只是一个剧本。如果您需要更多功能,那么您应该考虑使用 Xcode(以前称为 Applescript Studio)创建基于 Applescript 的应用程序。
You can't do this with Applescript. Saving an Applescript as an application really only removes the requirement of needing Script Editor to run the script as well as a couple other minor changes. In the end, it's still just a script. If you need more functionality, then you should look into creating Applescript-based applications with Xcode (in what used to be known as Applescript Studio).
使用 Xcode,执行以下操作:
第 4 条有点不稳定,因为我不记得具体是怎么进行的。我会给您一个进一步阅读的链接:http://cocoadevcentral.com/articles/000036.php< /a>.不过,将它与 applescript 链接应该不会有任何问题。
如果您能发布一个可行的解决方案(我的意思是当您让它发挥作用时),我将不胜感激。
br,
尤哈
With Xcode, do the following:
Bullet 4 is a bit shaky as I don't remember excatly how it goes. I'll give you a link for further reading: http://cocoadevcentral.com/articles/000036.php. There should not be any problems to link it with applescript, though.
I would appreciate if you could post a working solution (when you get it to work, I mean).
br,
Juha