Is there a way to trigger a Hot Key/Keyboard Shortcut via a Shell Script, a AppleScript or a Automator Workflow?

眉间皱痕 提交于 2019-12-08 05:17:21

问题


I'm an avid Keyboard Maestro user and I need a workaround for triggering a keyboard shortcut like ⌘⇧L (externally, without Keyboard Maestro). So I thought a bash script would be capable of doing such a thing. An AppleScript or an Automator workflow would be sufficient, too. I anybody could help me this would be great.


You don't have to read this, but here's why I want to do what I want to do:

I have a the same string assigned to various Markdown macros, I use a string instead of Hotkeys because it's much more memorable for me since my brain already is filled with so many application shortcuts. The disadvantage is that Keyboard Maestro won't delete the keystrokes of the string. I can perform several actions within the program to delete them but adding these actions for each and every macro is tedious and suboptimal.


回答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)

Reference of Mac key codes: lri.me/chars



来源:https://stackoverflow.com/questions/7810703/is-there-a-way-to-trigger-a-hot-key-keyboard-shortcut-via-a-shell-script-a-appl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!