Skip to content

Instantly share code, notes, and snippets.

@edenwaith
Last active May 29, 2022 07:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edenwaith/24a9529bfb871ec95150c07c748f4764 to your computer and use it in GitHub Desktop.
Save edenwaith/24a9529bfb871ec95150c07c748f4764 to your computer and use it in GitHub Desktop.
AppleScript: Count the number of open tabs in Google Chrome
-- CountOpenChromeTabs.scpt
-- Author: Chad Armstrong
-- Date: 30 August 2019
-- Description: Count the number of open tabs in Google Chrome
-- To run from CLI: osascript CountOpenChromeTabs.scpt
-- To create an alias command:
-- In ~/.bash_profile, add the line: alias counttabs='osascript ~/Projects/Scripts/CountOpenChromeTabs.scpt'
-- Refresh the bash shell environment: source ~/.bash_profile
tell application "Google Chrome"
--Variables
set windowlist to every window
set totaltabcount to 0
-- Loop through each window to count the number of open tabs
repeat with chromewindow in windowlist
try
set tabcount to number of tabs in chromewindow
set totaltabcount to totaltabcount + tabcount
on error errmsg
-- log "error message: " & errmsg
end try
end repeat
log "There are " & totaltabcount & " Chrome tabs open."
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment