AppleScript:如何获取未能加载的Safari选项卡的URL?

AppleScript:如何获取未能加载的Safari选项卡的URL?,safari,applescript,Safari,Applescript,以下是我获取URL的方式: tell application "Safari" set _URL to URL of current tab of front window end tell 对于成功打开的页面,我得到了正确的URL。但对于那些无法打开的用户,选项卡名称为“无法打开页面”,页面内容为“Safari找不到服务器”,URL不是真实的网站地址 我得到的是: file:///Applications/Safari.app/Contents/Resources/

以下是我获取URL的方式:

tell application "Safari"    
set _URL to URL of current tab of front window    
end tell    
对于成功打开的页面,我得到了正确的URL。但对于那些无法打开的用户,选项卡名称为“无法打开页面”,页面内容为“Safari找不到服务器”,URL不是真实的网站地址

我得到的是:

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


因此,当页面无法打开时,我如何才能获得Safari地址栏中的真正内容?

您可能仍然可以使用UI脚本实际获取地址字段中的文本

tell application "Safari" to activate
delay 0.1
tell application "System Events"
    tell process "Safari"
        key code 37 using {command down}
        key code 8 using {command down}
        delay 0.1
        key code 53
    end tell
end tell
set _URL to the clipboard

成功了!非常感谢你。还有很多东西要学。嗨,我能问一下你怎么知道我怎么知道钥匙密码吗?您可以在此处找到完整列表: