Tuesday, May 13, 2025

Trouble defining a Mac global keyboard shortcut to run an AppleScript or Automator workflow

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?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles