0

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 "tell application \"System Events\" to key code 64"

But trying

osascript -e "tell application \"System Events\" to key code 13 using {option down, shift down, command down}"

...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 "command-w":

osascript -e "tell application \"System Events\" to key code 13 using command down"

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 "tell application \"System Events\" to key code 13 using {control down, command down}"

This did not work either.

So how can I use multiple modifier keys here?

5
  • Okay, I downloaded Streamlabs+OBS-1.1.2.dmg and installed it. I then configured it and then assigned the keyboard shortcut of ⌥⇧⌘W in Hotkeys of its Preferences. Testing manually it worked. Testing from Script Editor it worked, Testing from Terminal it worked. However, while it does work, nonetheless, it requires some additional coding if one does not first activate Streamlabs OBS before System Events sends the key code. Note that it also requires settings under System Preferences > Security & Privacy > Privacy as well. Commented May 25, 2021 at 21:30
  • Thanks. I had already tried activating "Streamlabs OBS" first in the applescript but I could not get that to work. I had modified the privacy setting already.
    – StevieD
    Commented May 25, 2021 at 22:18
  • BTW, I found that others have reported very similar problems to me: obsproject.com/forum/threads/hotkeys-not-working-properly.69137 in a slightly different version of OBS which I believe OBS Streamlabs is forked from
    – StevieD
    Commented May 25, 2021 at 22:18
  • The point is, I did get ⌥⇧⌘W working using System Events to act on Streamlabs OBS, however it's somewhat moot since you were unwilling to provide the information I requested. IMO the issue is indeed Streamlabs OBS caused in how it implements its hotkeys, as I have no issue with triggering an Apple global keyboard shortcut using System Events, regardless of what has focus. Commented May 25, 2021 at 22:39
  • Ok. Whatever………………
    – StevieD
    Commented May 26, 2021 at 12:28

1 Answer 1

0

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 "1" 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 "tell application \"System Events\" to key code 83 using command down"

...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 "silent" 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .