Runar
Runar

Reputation: 85

Applescript to get the URL from Safari

I'm trying to get the URL from Safari, close the tab and open it in Chrome ( TUAW Post ) But I keep getting the error:

error "Safari got an error: Can’t get current tab." number -1728 from current tab

From the code line:

set theURL to URL of current tab of window 1

Any suggestions?

All the code:

property theURL : ""

tell application "Safari"

    set t set theURL to URL of current tab of window 1
    close current tab

end tell

tell application "Google Chrome"

    set URL of active tab of window 1 to theURL

    activate

end tell

Upvotes: 3

Views: 13102

Answers (2)

Runar
Runar

Reputation: 85

Thanks a lot guys! Here is the final code.

property theURL : ""

tell application "Safari"

    set theURL to URL of current tab of window 1

end tell

tell application "Google Chrome"

    tell window 1
        make new tab with properties {URL:theURL}
    end tell

    activate

end tell

Upvotes: 1

regulus6633
regulus6633

Reputation: 19040

It works for me...

tell application "Safari"
    set theURL to URL of current tab of window 1
end tell

You have to show more code because the error is caused by something else. Let me ask you this, do you have the tell application Safari statement inside of another tell block? Maybe it's inside the tell google chrome block of code? If so remove it.

Upvotes: 13

Related Questions