Skip to content

Instantly share code, notes, and snippets.

@henkin
Last active December 17, 2025 19:10
Show Gist options
  • Select an option

  • Save henkin/f776a3b4a54328fb6f6a5e5ebd18bafc to your computer and use it in GitHub Desktop.

Select an option

Save henkin/f776a3b4a54328fb6f6a5e5ebd18bafc to your computer and use it in GitHub Desktop.
appleScript
tell application "System Events"
-- 1. Get the process info safely
set front_process to first process whose frontmost is true
set front_app_pid to unix id of front_process
set front_app_name to name of front_process
end tell
-- Toggle Microsoft Teams
tell application "Microsoft Teams"
activate
delay 0.5
tell application "System Events"
keystroke "m" using {shift down, command down}
end tell
end tell
-- 2. Only attempt to switch back if we actually captured a valid PID/Name
-- This prevents the "Choose Application" dialog from appearing
if front_app_name is not missing value and front_app_name is not "" then
tell application "System Events"
set switchedBack to false
repeat with p in processes
if unix id of p is front_app_pid then
set frontmost of p to true
set switchedBack to true
exit repeat
end if
end repeat
end tell
-- Fallback: Only try name-based activation if PID method didn't finish the job
if not switchedBack then
try
tell application front_app_name to activate
end try
end if
end if
@henkin
Copy link
Author

henkin commented Dec 17, 2025

Mutes/unmutes Microsoft Teams
Assigned this as a keyboard shortcut in BTT - works great, from any app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment