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.