0

On my Mac, I've created an AppleScript within Script Editor:

-- https://support.microsoft.com/en-us/office/keyboard-shortcuts-for-microsoft-teams-2e8e2a70-e8d8-4a19-949b-4c36dd5292d2#PickTab=MacOS -- https://apple.stackexchange.com/questions/477933/trouble-defining-a-mac-global-keyboard-shortcut-to-run-an-applescript-or-automat -- Remember NOT to move your mouse while the script is running (i.e. when you use the hotkey). tell application "Microsoft Teams" to activate delay 0.1 tell application "System Events" -- Start a search: keystroke "g" using {command down} delay 0.5 -- Provide the search query: keystroke "example" -- a delay of at least 0.2 is required here: delay 0.2 keystroke return delay 0.2 -- Toggle "Unmuted" on and off: keystroke "q" using {option down, command down} keystroke "q" using {option down, command down} end tell 

If I press the button to run it manually, it works! 🎉

Now I want to set a global keyboard shortcut.

Regardless of which app has focus (whether I'm in Edge browser, Teams, VSC, or whatever), I want the keyboard shortcut to be honored, and it should run this script.

I've done this sort of thing before, but this time I'm having trouble.

I've tried using the Automator and Shortcuts apps too.

I'm very close, because if I press my Cmd Ctrl R shortcut while System Settings has focus, the script runs correctly and achieves the goal.

How can I make the shortcut work when any other app has focus?

1 Answer 1

0

It's working now.

Can only run AppleScript from Automator reminded me.

It's probably best to close all apps before defining the keyboard shortcut... for maybe 2 reasons.

  1. I had had so many apps open that I hadn't noticed certain permissions modals appearing in the background that I was supposed to click.

    I think it happens on the first usage of the keyboard shortcut from within an app.

    E.g. if you close all apps, define a keyboard shortcut, open VSC, try to use the keyboard shortcut, I think a popup will ask you to grant permission for the keyboard shortcut to work from that app (VSC, in this case).

    I hadn't been seeing those since they were popping up behind other apps.

  2. It might even be required to restart each app that you expect that you might ever want to have in focus while you use the keyboard shortcut.

    So by closing all apps first (before defining the shortcut), you're in the clear.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.