从OS X的Chrome上获取最前面标签的URL?
有没有办法做到这一点铬?从OS X的Chrome上获取最前面标签的URL?
tell application "Google Chrome"
return URL of front document as string
end tell
...不起作用。
由于没有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
现在,Chrome浏览器(7+)支持AppleScript的,你可以这样做:
tell application "Google Chrome"
get URL of active tab of first window
end tell
注: “第一窗口” 指的是最前面的窗口。
是否存在针对Chrome特定AppleScript命令的文档?例如,如果我想要执行诸如获取活动选项卡的HTML内容之类的东西,我在哪里寻找方法来做到这一点? – 2010-11-28 09:05:17
除了通过在脚本编辑器中打开Chrome应用程序可以看到的字典,我找不到多少文档。 – 2010-11-28 17:44:15
我认为你可以使用此脚本获得最前面的选项卡:
tell application "Google Chrome"
set frontIndex to active tab index of front window
get URL of tab frontIndex of front window
end tell
希望我得到这个权利。试试看。
或者只是告诉应用程序谷歌浏览器“告诉窗口1到标签活动标签索引的URL”。或者'告诉应用“谷歌浏览器”到窗口1的活动标签的URL。 – user495470 2011-10-18 23:55:56
有一种更简单的方法来检索URL。
'tell application "Google Chrome" to return URL of active tab of front window'
测试和工程就像一个魅力。
啊好吧,是的,这是非常好的做法,进入 – mcgrailm 2010-03-23 16:25:50
宇!我只写了下面的脚本,这样我就可以更容易地使用Chrome的PasswordMaker了,谢谢你的回答! 告诉应用程序“系统事件” \t告诉应用程序“谷歌浏览器” \t \t集theURL获得工具栏的文本字段1的值窗口的11 \t年底告诉 端告诉 集domainparts到splitText(” (“/”,theURL)中的项目3) 将域名部件的项目((“。”,{item((count count domainparts) - 1),domainparts的项目((count count domainparts))设置为topdom}) 请执行shell脚本“/ Users/dmd/bin/pmo”&topdom – dmd 2010-03-23 16:57:23
呃,好的,我该如何让它的格式正确? – dmd 2010-03-23 16:57:39