I wrote a quick script in response to a tweet from Brittany Smith in which she sought a solution for all the leftover Zoom tabs she had open in Safari after following a link that launched the Zoom app. I’m not in enough Zoom calls on a daily basis for this to be a real issue for me, but it was an easy enough script to whip up. I’m sharing it in case more people than just Brittany are in the same boat.

It should be noted that there’s a Safari extension called Zoom In that purports to provide a very elegant solution to this issue. I only hacked this together when Brittany said that the extension wasn’t working for her. Rather than bother trying to test it myself, I just wrote an AppleScript to handle it.

This will only work with Safari, but could easily be adapted to Chrome (and Brave, and probably Edge). It will never work with Firefox. Well, I shouldn’t say never, maybe someday Mozilla will get its AppleScript act together…

Here’s the script. You can trigger it from LaunchBar or Alfred, or use Automator to create a Workflow, Service, or App bundle. I’ll leave it at that. It’s working in my initial testing, but if you try it out and run into issues, please leave a comment or Tweet at me and I’ll update the gist with any fixes.

close zoom tabs.applescriptraw
"
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set tabsToClose to {}

tell application "Safari"
	-- cycle through all open windows
	repeat with _window in windows
		-- cycle through all tabs of given window
		repeat with _tab in tabs of _window
			-- if the URL is a zoom.us URL, add it to the list to close
			if URL of _tab contains "zoom.us" then
				-- we want the tabs in reverse order
				-- otherwise closing one throws the index off
				set beginning of tabsToClose to _tab
			end if
		end repeat
		-- close matching tabs in current window
		repeat with _tab in tabsToClose
			close _tab
		end repeat
	end repeat
end tell