【发布时间】:2010-03-20 12:46:48
【问题描述】:
有没有办法对 Chrome 执行此操作?
tell application "Google Chrome"
return URL of front document as string
end tell
...不起作用。
【问题讨论】:
有没有办法对 Chrome 执行此操作?
tell application "Google Chrome"
return URL of front document as string
end tell
...不起作用。
【问题讨论】:
现在 Chrome (7+) 支持 AppleScript,您可以这样做:
tell application "Google Chrome"
get URL of active tab of first window
end tell
注意:“第一个窗口”是指最前面的窗口。
【讨论】:
有一种更简单的方法来检索 URL。
'tell application "Google Chrome" to return URL of active tab of front window'
经过测试并像魅力一样工作。
【讨论】:
由于没有applescript 支持,唯一的办法就是通过GUI 脚本,我不确定您对applescript 的熟悉程度,但是gui 脚本是一个不好的做法。所以请谨慎使用此代码。同样重要您可以访问在您的通用访问首选项中启用的辅助设备。
tell application "Google Chrome"
activate
tell application "System Events"
tell application process "Google Chrome"
get value of text field 1 of tool bar 1 of window 1
end tell
end tell
end tell
【讨论】:
我认为您可以使用此脚本获得最前面的选项卡:
tell application "Google Chrome"
set frontIndex to active tab index of front window
get URL of tab frontIndex of front window
end tell
希望我做对了。试试看。
【讨论】:
tell app "Google Chrome" to tell window 1 to URL of tab active tab index。或tell app "Google Chrome" to URL of active tab of window 1.