MacOS: Arbitrary keyboard shortcuts
I’ve had to configure this three times now, and I forget each time. So here’s how to do it:
- System Preferences; Security and Privacy; Privacy; Accessibility - add Automator to this list.
- Open Automator; create a new Service
- Set “Service receives” (dropdown at the top) to “No input” and make sure “in any application” is selected.
- Add the event type that you want - eg for my “Lock Screen” shortcut I choose “Activate Screensaver”. For “New Terminal” I have to use “Run AppleScript” instead.
- Once you’re finished, save the Service.
- Head back to System Preferences; Keyboard; Shortcuts. Under the “Services” option, add your desired key combination as the shortcut.
It should now work!
Code for starting a Terminal
I’m not sure where I got this, I’m quite sure I did not write it:
on run {input, parameters}
tell application "Terminal"
if it is running then
do script ""
end if
activate
end tell
end run
Note that for any AppleScript, you’ll probably get a security prompt the first time you use it in each application.