osascript to trigger a hot key with multiple modifier keys in OBS Streamlabs is not working I want to activate a hotkey in OBS Streamlabs with applescript/osascript.
So this works perfectly fine and as expected using the F17 key (I have a larger keyboard with a numpad):
osascript -e &quot;tell application \&quot;System Events\&quot; to key code 64&quot;
But trying
osascript -e &quot;tell application \&quot;System Events\&quot; to key code 13 using {option down, shift down, command down}&quot;
...doesn't work.
When I type option-shift-command-w manually on the keyboard, however, the hot key is triggered.
Here's the strange thing: I can trigger the hotkey if it's simpler, like &quot;command-w&quot;:
osascript -e &quot;tell application \&quot;System Events\&quot; to key code 13 using command down&quot;
Running this command will trigger the command-w global hot key and closes out the current app.
Quoting the curly braces used with the compound modifier keys did not help. I also tried a simpler, 3-keypress combo:
osascript -e &quot;tell application \&quot;System Events\&quot; to key code 13 using {control down, command down}&quot;
This did not work either.
So how can I use multiple modifier keys here?
OK, here is a workaround to the problem. Unfortunatley, this really isn't an answer as it doesn't explain why, at the lower OS level, the problem exists in the first place. It just works around the limitation by mapping key strokes with one or more modifiers to single keystrokes. Perhaps people who are more familiar with the keyboard at the lower levels of the OS can use this solution to figure out what might be happening.
Anyway, as mentioned, OBS Streamlabs can respond to single keystrokes as hotkeys that are simulated with applescript. For example, you can tell OBS to recognize &quot;1&quot; on the number pad as a hotkey. The problem, of course, is that using a single key as a hotkey will also generate that character in the terminal or any other app you are working in. So the trick is to tell OBS to set up a hotkey for numkey 1 and then remap a key stroke with one or more modifier keys to that single numkey 1 keystroke.
The low-level remapping can be accomplished with the free app Karabiner elements
So, using the app, I remapped the command + Num-1 combination to Num-1. So now when I run this simple script from the command line...
osascript -e &quot;tell application \&quot;System Events\&quot; to key code 83 using command down&quot;
...no character gets printed by the key stroke simulated by the one-liner above and the hotkey now gets triggered.
By they way, I could not figure out how to send keyboard output generated by an apple script to /dev/null. It doesn't appear to be possible, as best I can tell. So something like command + Num-1 that creates a &quot;silent&quot; keystroke is needed.
So, with this method, I can have a hotkey for all the rarely used keys on the keypad. I can also use all function keys that are not getting used by another app.