Skip to content

Instantly share code, notes, and snippets.

@beautyfree
Last active April 27, 2020 11:13
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 beautyfree/903dc22ac04056e8fc0acf5486c0e827 to your computer and use it in GitHub Desktop.
Save beautyfree/903dc22ac04056e8fc0acf5486c0e827 to your computer and use it in GitHub Desktop.
Keyboard Maestro Script Chrome Example / thx @nikitavoloboev
tell application "Keyboard Maestro Engine"
set urlToFetch to getvariable "urlToFetch"
end tell
set _win to false
tell application "Google Chrome"
set {idList, urlList} to {id, URL} of every tab of every window
end tell
set AppleScript's text item delimiters to linefeed
if (urlList as text) contains urlToFetch = true then
set theWin to 1
repeat with i in urlList
set theTab to 1
repeat with n in i
if n starts with urlToFetch then
set {_win, _tab} to {theWin, theTab}
end if
set theTab to theTab + 1
end repeat
set theWin to theWin + 1
end repeat
end if
if _win ≠ false then
tell application "System Events"
if quit delay ≠ 0 then set quit delay to 0
tell process "Google Chrome"
perform action "AXRaise" of window _win
end tell
end tell
tell application "Google Chrome"
tell front window to set active tab index to _tab
end tell
else
tell application "Google Chrome"
tell front window
make new tab at end of tabs with properties {URL:urlToFetch}
end tell
end tell
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment