使用 AppleScript 抓住最顶层窗口显示在 web 浏览器中的 URL: 最终名单

52 篇文章 0 订阅

原文连接:http://d2100.com/questions/67271

我建立抓、 在 Safari 中最前面的窗口中的 URL [构件] [1]然后允许您缩短它使用尽管 API。作为工程甜。

我想让这更加灵活,所以我正在研究如何抓住从其他浏览器的 URL。这里是在 Safari 中工作的 AppleScript:

tell application "Safari"
    return URL of front document as string
end tell

一些挖之后, 我确定,以下可能为火狐工作 (尽管一个人已经告诉我它不工作对他来说,可能是一些扩展名的冲突?):

tell application "Firefox"
    set myFirefox to properties of front window as list
    return item 3 of myFirefox
end tell

注: 以上是少比最佳实践,依赖于列表项的位置的一个示例。请参阅下面的更好的解决方案 Firefox。

我想做的是在 Mac 上生成一个明确对应词的所有现代浏览器的列表: 歌剧、 朝圣、 羊群。

更新:我谈一谈有关的研究,我碰到一个有用的线程在MacOSXHints.com上。我的答案下面的大部分都基于这种讨论。

更新 2:我已经将此页上的 AppleScript 纳入 [构件] [1]。这似乎是工作膨胀。

回答 #1

这是皮耶罗再次回一个新的 id (我失去了我的 cookie 尝试重新安装火狐时!!!)。

我只被试图火狐 304 什么改变有关 appleScript 支持和 relyability。仍是相同的 bug...

我的测试和登陆的网站,搜索带我到你不能访问窗口的名称和其他属性的窗口,例如 «类卷曲»,在同一脚本中的结论。

如果您正在使用的名称窗口,以及,suddently,您不能访问它不再 (以获取随机二进制字符串一样),您必须再次调用此代码:

tell application "Firefox" to activate

使用任何将在火狐中生成错误的语句还将努力就好,使窗口名称再次,可用,但重新启动你的 Mac 不会改变任何东西 !

一旦你已经做了,正如我前面提到,您不能访问 «类卷曲» 不再,直到下一个 Firefox 重新启动...

在 Mac 上的火狐编写脚本真的是使命是不可能的 !

如果您想 AppleScript 要支持 Firefox 上告诉它,和这个 bug 投票支持 !!!

https://bugzilla.mozilla.org/show_bug.cgi?id=464701

回答 #2

激活用户界面的脚本,然后运行下面的代码。你会有该 URL 在剪贴板中,您可以将其粘贴。

tell application "Firefox" to activate
tell application "System Events"
    keystroke "l" using command down
    keystroke "c" using command down
end tell

回答 #3

Google Chrome 的 Mac 已添加的 AppleScripting 方法,用于获取 URL。

这里是铬 AppleScript SDK

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

回答 #4

火狐 3.03,将隐藏从 AppleScript 所有的窗口属性,包括 «类卷曲»,如果您使用的语句将类似于以下之前的当前有一个 bug:

tell application "Firefox" to activate

tell application "Firefox"
 if (front window) exists then do_something()
end tell

变通办法是,而是使用下面的代码:

tell application "System Events"
 tell process "Firefox"
  set frontmost to true
  set xsist to (front window) exists
  (* keep xsist value to test later on *)
 end tell
end tell

注:窗口的属性将继续直至下一步重建香港经济活力的 Firefox,在国际间不可用

回答 #5

卡米诺 1.6 及以上:

tell application "Camino"
    return URL of current tab of front browser window as text
end tell

与早前的答复中,不同的是这将得到聚焦选项卡的 URL。

回答 #6

火狐 (2.0.0.14 和 3.0.1 版上测试):

tell application "Firefox"
    set myURL to «class curl» of window 1
    return myURL
end tell

回答 #7

卡米诺 (测试版本 1.6.4):

tell application "Camino"
    set p to properties of front tab of front window
    return |currentURI| of p as string
end tell

回答 #8

OmniWeb (测试版 5.8 上):

tell application "OmniWeb"
    set myInfo to GetWindowInfo
    return item 1 of myInfo
end tell

回答 #9

歌剧 (9.21 和 9.62 版本上进行测试):

tell application "Opera"
    return URL of front document as string
end tell

回答 #10

羊群 (在 2.0 版上测试):

tell application "Flock"
    set p to properties of front window as list
    return item 3 of p
end tell

这依赖于该列表项的位置,但据我所知,这是唯一能到达此值。该财产命名为 address ,尽管苹果公司的文档没有这么说,似乎是 AppleScript 中的保留的字。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值