rein
rein

Reputation: 33465

Closing specific tab in FireFox using AppleScript

I need to script the closing of tabs with specific titles in FireFox. Is there a FireFox equivalent to the AppleScript examples below?

Close tabs in Safari:

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

Close tabs in Chrome:

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

Upvotes: 2

Views: 3826

Answers (1)

Gannet
Gannet

Reputation: 1453

Since Firefox doesn't have any AppleScript support you'll need to rely on UI scripting. Of course, Firefox's non-standard UI doesn't help either but it's still possible. Try this:

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

Upvotes: 5

Related Questions