Getting the URL of current Chrome tab

Hello,

Hi! I am trying to implement a keyboard shortcut that does the following:

  1. tell application "Google Chrome" to get URL of active tab of front window
  2. set variable URL to result
  3. do shell script "/Users/YOUR-USER-NAME/.nvm/versions/node/v13.5.0/bin/node ~/PLACE-WHERE-YOU-CLONED-THE-REPOSITORY/hypothesis-to-bullet/index.mjs "& URL &" YOUR-HYPOTHESIS-USERNAME | pbcopy"

But I am stuck on item 1!

How would you go around getting the URL into a variable?

Thanks!!

tell application "Google Chrome"
	
	set result to get URL of active tab of front window
	
end tell
2 Likes

You don't need to mess with Apple Script. This is easily implemented in via "Execute Shell Script / Task" action and google-cli which on mac can be installed with homebrew.

chrome-cli --help
Usage:
chrome-cli -h (Print help)
chrome-cli --help (Print help)
chrome-cli help (Print help)
chrome-cli list windows (List all windows)
chrome-cli list tabs (List all tabs)
chrome-cli list tabs -w (List tabs in specific window)
chrome-cli list links (List all tabs' link)
chrome-cli list links -w (List tabs' link in specific window)
chrome-cli info (Print info for active tab)
chrome-cli info -t (Print info for specific tab)
chrome-cli open (Open url in new tab)
chrome-cli open -n (Open url in new window)
chrome-cli open -i (Open url in new incognito window)
chrome-cli open -t (Open url in specific tab)
chrome-cli open -w (Open url in new tab in specific window)
chrome-cli close (Close active tab)
chrome-cli close -w (Close active window)
chrome-cli close -t (Close specific tab)
chrome-cli close -w (Close specific window)
chrome-cli reload (Reload active tab)
chrome-cli reload -t (Reload specific tab)
chrome-cli back (Navigate back in active tab)
chrome-cli back -t (Navigate back in specific tab)
chrome-cli forward (Navigate forward in active tab)
chrome-cli forward -t (Navigate forward in specific tab)
chrome-cli activate -t (Activate specific tab)
chrome-cli size (Print size of active window)
chrome-cli size -w (Print size of specific window)
chrome-cli size (Set size of active window)
chrome-cli size -w (Set size of specific window)
chrome-cli position (Print position of active window)
chrome-cli position -w (Print position of specific window)
chrome-cli position (Set position of active window)
chrome-cli position -w (Set position of specific window)
chrome-cli source (Print source from active tab)
chrome-cli source -t (Print source from specific tab)
chrome-cli execute (Execute javascript in active tab)
chrome-cli execute -t (Execute javascript in specific tab)
chrome-cli chrome version (Print Chrome version)
chrome-cli version (Print application version)

1 Like