2

我需要在 FireFox 中编写关闭具有特定标题的选项卡的脚本。是否有与下面的 AppleScript 示例等效的 FireFox?

关闭 Safari 中的标签页:

tell application "Safari"
    delete (every tab of every window where its name contains "[done]")
end tell

在 Chrome 中关闭标签页:

tell application "Google Chrome"
    delete (every tab of every window where its title contains "[done]")
end tell
4

1 回答 1

5

由于 Firefox 没有任何 AppleScript 支持,因此您需要依赖 UI 脚本。当然,Firefox 的非标准 UI 也无济于事,但仍有可能。试试这个:

tell application "System Events" to tell process "firefox"
    set frontmost to true
    repeat with w from 1 to count of windows
        perform action "AXRaise" of window w
        set startTab to name of window 1
        repeat
            if name of window 1 contains "[done]" then
                keystroke "w" using command down
            else
                keystroke "}" using command down
            end if
            delay 0.2
            if name of window 1 is startTab then exit repeat
        end repeat
    end repeat
end tell
于 2012-09-15T06:17:04.130 回答