如何检查 mac bash 应用程序启动时是否按下了选项键
我有一个相对简单的问题。
我有一些 Mac 应用程序,其启动器是用 bash 编写的。 我想向启动器添加一个小功能,让其他人在应用程序启动时按“option/alt”键时访问 config.app 或位于 /Contents/Resources 中的其他内容。有点像 iTunes 或 iPhoto,您可以在其中访问一个小选项菜单。
我不知道纯粹在 bash 中的代码应该是什么样子;我发现了一些使用 applescript 和/或 cocoa hooks 的例子,但没有一个纯粹在 bash 中。
类似于: if 'optionKeyDown';然后打开“$WORKDIR/../Resources/config.app”
或者这在纯 bash 中根本不可能?
I got a relatively simple question.
I have a few mac applications that have launchers written in bash.
I wanted to add a little feature to the launchers, by letting others access a config.app or something else located in /Contents/Resources, when they press the 'option/alt' key at the startup of the app. Kinda like iTunes or iPhoto, where you can access a little options menu.
I don't know how the code should look like when it's purely in bash; i found a few examples that make use of applescript and/or cocoa hooks, but none purely in bash.
Something like: if 'optionKeyDown'; then open "$WORKDIR/../Resources/config.app"
Or is this not possible in pure bash at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有一个很好的解决方案: http://lists.apple.com /archives/applescript-users/2009/Sep/msg00374.html
获取以下代码:
将其粘贴到名为keys.m 的文件中。
然后构建一个像这样的命令行实用程序:
将
keys
可执行文件放在路径中的某个位置,例如/usr/local/bin
,甚至放在与 bash 相同的目录中脚本,然后您可以将其称为keys option
并检查返回的字符串是否为“0”或“1”。There's a good solution here: http://lists.apple.com/archives/applescript-users/2009/Sep/msg00374.html
Take the following code:
Paste it into a file called, e.g. keys.m.
Then build a command line utility like this:
Put the
keys
executable somewhere in your path, e.g./usr/local/bin
, or even just in the same directory as your bash script, then you can call it as e.g.keys option
and check the returned string for "0" or "1".