Skip to content

Instantly share code, notes, and snippets.

@scoates
Last active March 6, 2023 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scoates/365fee4ed2930005b6f954545b3c5dcf to your computer and use it in GitHub Desktop.
Save scoates/365fee4ed2930005b6f954545b3c5dcf to your computer and use it in GitHub Desktop.
How to end the Zoom-steals-focus-on-launch nightmare we've all been experiencing.
-- You need Hammerspoon to run this: http://www.hammerspoon.org/
-- Zoom is a focus nightmare. This script will steal focus back from Zoom for zoomBlockTime seconds, at launch.
-- If you don't switch to another app Zoom will stay active.
-- If you activate (focus) Zoom from Finder, it'll accept your focus change.
-- If you focus, say, your chat app to tell someone you've launched your Zoom meeting, focus will switch back
-- to that app every time Zoom tries to steal it. Today, it's 5 times on my machine.
zoomBlockTime = 10
zoomFocusBlocked = false
foregroundAppName = nil
function zoomWatch(appName, eventType, appObject)
-- watch for launch event and start a timer
if (appName == "zoom.us" and eventType == hs.application.watcher.launched) then
hs.alert("Zoom Launched. Focus theft blocked for " .. tostring(zoomBlockTime) .. " seconds.")
zoomFocusBlocked = true
hs.timer.doAfter(zoomBlockTime, function()
zoomFocusBlocked = false
hs.alert("Zoom focus unblocked.")
end)
end
-- handle focus theft if zoom is launch-blocked, unless it's from Finder
if (zoomFocusBlocked and foregroundAppName ~= nil and appName == "zoom.us" and eventType == hs.application.watcher.activated) then
if (foregroundAppName == "Finder") then
hs.alert("Zoom activated from Finder. Allowed.")
else
hs.alert("Zoom tried to activate from " .. foregroundAppName .. "; denied")
-- reset activation
hs.application.get(foregroundAppName):activate()
print("Reset activation to " .. foregroundAppName)
end
elseif (appName ~= nil and appName ~= "zoom.us" and eventType == hs.application.watcher.activated) then
foregroundAppName = appName
print("foregroundAppName set to " .. appName)
end
end
zoomWatcher = hs.application.watcher.new(zoomWatch)
zoomWatcher:start()
@scoates
Copy link
Author

scoates commented Mar 6, 2023

Short screen cap demo.

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