-
-
Save avh4/f4ba50e10c768bddc958af4122e44c22 to your computer and use it in GitHub Desktop.
AppleScript: Count the number of open tabs in Safari
This file contains 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
-- CountOpenSafariTabs.scpt | |
-- Author: Chad Armstrong | |
-- Date: 13 May 2016 | |
-- Description: Count the number of open tabs in Safari | |
-- To run from CLI: osascript CountOpenSafariTabs.scpt | |
tell application "Safari" | |
--Variables | |
set winlist to every window | |
set totaltabcount to 0 | |
-- Loop through each window to count the number of open tabs | |
repeat with win in winlist | |
try | |
set tabcount to number of tabs in win | |
set totaltabcount to totaltabcount + tabcount | |
-- log "tab count: " & tabcount & " totaltabcount: " & totaltabcount | |
on error errmsg | |
-- Often getting error message like this: | |
-- "Safari got an error: AppleEvent handler failed." | |
-- log "error message: " & errmsg | |
end try | |
end repeat | |
log "There are " & totaltabcount & " Safari tabs open." | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment