首页 > 解决方案 > 苹果脚本。Firefox 中的窗口名称

问题描述

我想知道 Firefox 中的窗口和选项卡的鬃毛。与其他浏览器配合良好的东西在这里会出现问题。例如:

tell application "Firefox" to get the name of every window

在 Firefox 浏览器中,我有一个带有 apple.com 的窗口和另一个带有 google.com 的窗口,但是脚本给了我这个奇怪的结果:

{"Google", "Apple", "", "", "Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more", "https://www.mozilla.org/en-US/firefox/new/?redirect_source=firefox-com", "", "", ""}

Amazon 和 mozilla 名称是我确信已关闭的以前的窗口。它还显示了几个“”,我不知道它们来自哪里。

如果我转到文档并单击 Firefox,它说我打开了两个窗口:

Apple
Google

所以,我不明白脚本的结果。为什么它给了我更多信息。

如何获取在 Firefox 中打开的窗口的名称(包括选项卡,如果可能)

标签: applescript

解决方案


这是获取所有 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
        delay 0.05
        set myTitle to (name of front window)
        copy myTitle to the end of the |tabList|
        set counter to counter + 1
    end repeat
end tell

tabList

在使用全局快捷方式搜索选项卡时,我使用了类似的方法。


推荐阅读