16

Is there a way to do this to Chrome?

tell application "Google Chrome" return URL of front document as string end tell 

... doesn't work.

0

5 Answers 5

48

Now that Chrome (7+) supports AppleScript, you can do this:

tell application "Google Chrome" get URL of active tab of first window end tell 

Note: "first window" refers to the frontmost window.

Sign up to request clarification or add additional context in comments.

3 Comments

Is there documentation for Chrome specific AppleScript commands? For example, if I want to do something like getting the HTML content of the active tab, where do I look for ways to doing it?
There isn't much documentation that I could find, except the dictionary that you can see by opening the Chrome app in Script Editor.
This stopped working in Chrome 103.0.5060.53.
8

There is a simpler way to retrieve the URL.

'tell application "Google Chrome" to return URL of active tab of front window'

Tested and works like a charm.

Comments

4

Since there is no applescript support the only way it can be done is through GUI scripting, I'm not sure how familiar you are with applescript but gui scripting is a bad practice to get into. so take this code with caution. it is also important that you have access for assistive devices ENABLED in your Universal Access preferences.

 tell application "Google Chrome" activate tell application "System Events" tell application process "Google Chrome" get value of text field 1 of tool bar 1 of window 1 end tell end tell end tell 

2 Comments

Woo! I just wrote the following script so I can more easily use PasswordMaker with Chrome, thanks to your answer! tell application "System Events" tell application process "Google Chrome" set theURL to get value of text field 1 of tool bar 1 of window 1 end tell end tell set domainparts to splitText(".", item 3 in splitText("/", theURL)) set topdom to joinText(".", {item ((count domainparts) - 1) of domainparts, item ((count domainparts)) of domainparts}) do shell script "/Users/dmd/bin/pmo " & topdom
you can't put code in comments they are just comments you can edit your question and put your final code at the bottom making sure you mark it
0

No Applescript support: Issue 27468 - chromium - Applescript support for testing and scripting - Project Hosting on Google Code

Comments

0

I think you can get the frontmost tab with this script:

tell application "Google Chrome" set frontIndex to active tab index of front window get URL of tab frontIndex of front window end tell 

Hope I got this right. Try it out.

1 Comment

Or just tell app "Google Chrome" to tell window 1 to URL of tab active tab index. Or tell app "Google Chrome" to URL of active tab of window 1.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.