Jump to content

Working on sending Safari tab to Chrome get stuck acquiring the URL


Recommended Posts

I use AppleScript to get this job done. 

 

Here's how I try to get the URL:

tell application "Safari"
set _URL to URL of current tab of front window
end tell 

 

For most of the page who successfully opened, I got the right URL. But for those who failed to open, which state "Failed to open page" as the tab name and "Safari Can't Find the Server" in the page content, the URL is not the real website address.

What I got is:

file:///Applications/Safari.app/Contents/Resources/

So how can I get what is really in the Safari address bar when the page failed to open?

 

Thanks guys.

 

Link to comment

 

This will set theURL to the contents of the URL bar.

 

tell application "System Events"
	tell process "Safari"
		set theURL to value of text field 1 of group 2 of toolbar 1 of window 1
	end tell
end tell

It's perfect! Many thanks.

Can I ask about how do you know that the url bar is the gourp 2 of toolbar 1?

If I want to know more, where can I get the documents or instructions include these information(which component is which)?  

Link to comment

I found that one on Stack Overflow, tbh.

 

The text field, toolbar and window are fairly obvious. I guess you would just use trial and error to figure out the group.

 

hey thanks anyway. In case you are interested, I've googled a solution: you can use an app comes with xcode called "accessibility inspector". :-)

Link to comment

hey thanks anyway. In case you are interested, I've googled a solution: you can use an app comes with xcode called "accessibility inspector". :-)

 

That is probably the best way to get it, but, it seems, for me, that the fastest way to get it is to do what Dean did and just look on StackOverflow. AppleScript is just so idiosyncratic.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...