songcrates Posted December 18, 2014 Posted December 18, 2014 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 windowend 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.
deanishe Posted December 18, 2014 Posted December 18, 2014 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
songcrates Posted December 20, 2014 Author Posted December 20, 2014 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)?
deanishe Posted December 20, 2014 Posted December 20, 2014 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.
songcrates Posted December 21, 2014 Author Posted December 21, 2014 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". :-)
rice.shawn Posted December 21, 2014 Posted December 21, 2014 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now