问题描述
我构建了一个 [widget][1],它从 Safari 最前面的窗口中获取 URL,然后允许您使用 tr.im API 缩短它.工作得很好.
I built a [widget][1] that grabs the URL from the frontmost window in Safari, then allows you to shorten it using the tr.im API. Works sweet as.
我想让它更灵活,所以我正在研究如何从其他浏览器获取 URL.这是适用于 Safari 的 AppleScript:
I want to make this more flexible, so am investigating how to grab an URL from other browsers. Here's the AppleScript that works in Safari:
tell application "Safari"
return URL of front document as string
end tell
经过一些挖掘之后,我确定以下可能适用于 Firefox(尽管有人告诉我这对他不起作用,可能与某些扩展有冲突?):
After some digging, I determined that the following might work for Firefox (though one person has told me it doesn't work for him, possibly a conflict with some extension?):
tell application "Firefox"
set myFirefox to properties of front window as list
return item 3 of myFirefox
end tell
注意:以上是一个不太好的实践的例子,依赖于列表项的位置.请参阅下文以获得更好的 Firefox 解决方案.
我想做的是在此处为 Mac 上的每个现代浏览器(Opera、Camino、Flock 等)建立一个最终等效物的列表.
What I'd like to do is build a list here of the definitive equivalents for every modern browser on the Mac: Opera, Camino, Flock, etc.
更新:在我对该主题的研究中,我在 MacOSXHints.com.我下面的大部分答案都基于该讨论.
Update: In my research on the subject, I came across a helpful thread on MacOSXHints.com. Most of my answers below are based on that discussion.
更新 2: 我已将此页面上的 AppleScript 合并到 [widget][1] 中.它似乎运行良好.
Update 2: I've incorporated the AppleScript on this page into the [widget][1]. It seems to be working swell.
推荐答案
Mac 版 Google Chrome 已添加用于获取 URL 的 AppleScripting 方法.
Google Chrome for Mac has added the AppleScripting method for getting the URL.
https://sites.google.com/a/chromium.org/dev/developers/design-documents/applescript
tell application "Google Chrome"
get URL of active tab of window 1
end tell
此处有更多示例:
http://laclefyoshi.blogspot.com/2010/10/google-chrome-ver.html
这篇关于使用 AppleScript 从 Web 浏览器最前面的窗口中获取 URL:最终列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!