Firefox是否提供AppleScript支持以获取Windows的URL?

时间:2013-07-25 00:14:10

标签: firefox applescript

我正在尝试编写一个AppleScript,除其他外,它会获取Firefox中每个打开的网页的URL。

在Safari(和Chrome)中,这非常简单:

tell application "Safari" to return URL of every tab in every window

然而,在我看来,Firefox并没有提供真正的AppleScript支持,例如获取任何标签或窗口的URL。当我同时使用术语“Firefox”和“AppleScript”时,我主要收到Firefox错误请求,要求恢复AppleScript支持,最后更新于2010年或2011年(如thisthis)。< / p>

我是否正确地想,Firefox不再提供任何正确的AppleScript支持?我意识到有一些半解决方法,例如在AppleScript中模拟键命令,但这些对我的目的来说并不实用。

4 个答案:

答案 0 :(得分:7)

要查看Firefox响应的所有AppleScript命令,请启动AppleScript编辑器,选择菜单File > Open Dictionary...,然后选择Firefox应用程序。

你会发现你所期待的:Firefox没有提供任何有用的AppleScript命令。

答案 1 :(得分:2)

Firefox 3.5及更早版本支持此功能,即使该命令在字典中不可见:

tell application "Firefox"
    get «class curl» of window 1
end tell

Firefox 3.6删除了此功能,截至目前(Firefox 22.0)尚未恢复。

答案 2 :(得分:0)

自2002年以来,Firefox团队一直working on this

同时,您可以使用UI编程来获取最前面的标签的URL

tell application "System Events" to tell process "Firefox"
    get value of text field 1 of combo box 1 of toolbar 2 of group 1 of front window
end tell

可与68.0.2版一起使用,但在将来的Firefox更新中可能会被破坏。

答案 3 :(得分:0)

这适用于 Firefox。不过,它并不是那么漂亮:)

tell application "Firefox"
    activate
    tell application "System Events" to keystroke "1" using command down
    set firstTitle to name of front window
    
    set tabList to {}
    set myTitle to "__f_o_o_b_a_r__" -- some random initial name
    set counter to 0 -- make sure that loop ends
    
    repeat until (counter > 100 or myTitle is equal to firstTitle)
        tell application "System Events" to key code 121 using control down
        tell application "System Events" to keystroke "l" using command down
        tell application "System Events" to keystroke "c" using command down
        delay 0.1
        set myTitle to (name of front window)
        copy (the clipboard) to the end of the |tabList|
        set counter to counter + 1
    end repeat
end tell

tabList

searching for tabs using a global shortcut 时我使用类似的方法。