How to get the current address of Safari's address bar with AppleScript
-
27-06-2021 - |
質問
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.
所属していません StackOverflow