【问题标题】:Does Firefox offer AppleScript support to get URL of windows?Firefox 是否提供 AppleScript 支持来获取窗口的 URL?
【发布时间】:2013-07-24 16:37:23
【问题描述】:

我正在尝试编写一个 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)。

那么,我认为 Firefox 不再提供任何适当的 AppleScript 支持是对的吗?我意识到有一些半解决方法,例如在 AppleScript 中模拟按键命令,但这些对我的目的来说并不实用。

【问题讨论】:

标签: firefox applescript


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      【解决方案3】:

      Firefox 团队一直是 working on this,显然是从 2002 年开始

      同时,您可以使用 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 更新中被破坏。

      【讨论】:

        【解决方案4】:

        这适用于 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 时我使用类似的方法。

        【讨论】:

        • 这是一个有趣的解决方法,不幸的是,它不会产生一致的结果,具体取决于当前在多标签窗口上选择了哪个标签。此外,它返回的 listnames 不在 windowtab 顺序中。
        猜你喜欢
        • 2011-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-29
        相关资源
        最近更新 更多