I want to read the address out of the address bar of a safari window with AppleScript.

One can use keystroke-simulating with cmd+l, cmd+c and subsequently read out the clipboard. But this is obviously a very ugly hack.

有帮助吗?

解决方案

Something like this should work to get the URL of the active tab in the last used window;

tell application "Safari"
    set w to first window
    set t to current tab of w
    display dialog (URL of t as string)
end tell

其他提示

tell application "Safari" to URL of document 1 would also work if the frontmost window isn't a normal browser window.

You can get the text on the location bar with tell application "System Events" to tell process "Safari" to value of text field 1 of group 2 of tool bar 1 of window 1 in Safari 6.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top