Skip to content

Instantly share code, notes, and snippets.

@jcla1
Last active December 22, 2015 20:19
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 jcla1/6525572 to your computer and use it in GitHub Desktop.
Save jcla1/6525572 to your computer and use it in GitHub Desktop.
Get the URL of Chrome's active tab.
tell application "System Events"
set chromeRunning to (length of (get name of every process whose name is "Google Chrome") is greater than 0)
set chromeInFocus to ((name of first application process whose frontmost is true) is "Google Chrome")
set activeURL to ""
set numTabs to 0
if chromeRunning then
tell application "Google Chrome"
set normalWindows to (windows whose mode is not "incognito")
if length of normalWindows is greater than 0 then
set activeURL to (get URL of active tab of (first item of normalWindows))
end if
repeat with w in normalWindows
set numTabs to numTabs + (length of (get tabs of w))
end repeat
end tell
end if
end tell
(chromeRunning as integer) & "," & (chromeInFocus as integer) & "," & numTabs & "\n" & (activeURL) as string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment