【问题标题】:Is there a way to trigger a Hot Key/Keyboard Shortcut via a Shell Script, a AppleScript or a Automator Workflow?有没有办法通过 Shell 脚本、AppleScript 或 Automator 工作流程触发热键/键盘快捷键?
【发布时间】:2011-12-10 06:36:33
【问题描述】:

我是一名狂热的 Keyboard Maestro 用户,我需要一种解决方法来触发像 ⌘⇧L 这样的键盘快捷键(在外部,没有 Keyboard Maestro)。所以我认为 bash 脚本能够做这样的事情。 AppleScript 或 Automator 工作流程也足够了。如果有人可以帮助我,那就太好了。


您不必阅读此内容,但这就是我想做我想做的事情的原因:

我有一个相同的字符串分配给各种 Markdown 宏,我使用字符串而不是热键,因为它对我来说更难忘,因为我的大脑已经充满了很多应用程序快捷方式。缺点是键盘大师不会删除字符串的击键。我可以在程序中执行几个操作来删除它们,但是为每个宏添加这些操作既乏味又不理想。

【问题讨论】:

    标签: bash applescript shortcut hotkeys automator


    【解决方案1】:
    tell application "System Events" to keystroke "l" using command down & shift down
    

    【讨论】:

    • 太好了!它非常易于使用,而且我无需任何深入的知识就能准确地产生我想要的行为。非常感谢,这对我来说是一个救生员。现在我可以疯狂使用各种宏和触发器了。
    【解决方案2】:
    tell application "System Events"
        key code {123, 124} using {shift down, command down} -- ⇧⌘←, ⇧⌘→
        keystroke "c" using command down -- keystroke "C" would be treated as ⇧C
    end tell
    delay 0.02 -- you need a small delay here before the next command
    set txt to Unicode text of (the clipboard as record)
    

    Mac 键码参考:lri.me/chars

    【讨论】:

    • 嗨,Lri,感谢您抽出宝贵的时间来写这个答案。在您的脚本和来自 Mac App Store 的Key Codes 的帮助下,我能够制作各种快捷方式。遗憾的是,该脚本不适用于 Keyboard Maestro,因为通过触发的快捷方式打开的宏立即关闭。必须有某种“输入”功能。无论如何,这个脚本也非常有用,因为我可以分配不同的击键并修改文本,这也很棒。这就像调整系统的键绑定。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多