Last active
March 6, 2023 03:47
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Short screen cap demo.