Thursday, April 10, 2008

  • More fun with AppleScript - closing tabs in Safari

    I go through a lot of browser tabs when I'm working, so I needed to cook up a way to quickly close a bunch of tabs in Safari. Safari already has a way to close all tabs except the current tab, so we just need a way to close tabs to the left or to the right of the current tab. AppleScript to the rescue!

    First, the left tabs:

    tell application "Safari"
    set cWindow to first item of windows
    set ctIndex to index of current tab of cWindow
    repeat ctIndex - 1 times
    close first item of tabs of cWindow
    end repeat
    end tell
    open location "x-launchbar:hide"

    Then, the right:

    tell application "Safari"
    set cWindow to first item of windows
    set ctIndex to index of current tab of cWindow
    repeat while (count of tabs of cWindow) > ctIndex
    close last item of tabs of cWindow
    end repeat
    end tell
    open location "x-launchbar:hide"

    I save those as "Close Left Tabs" and "Close Right Tabs" in ~/Library/Scripts. When I need to use them, I just bang a couple of keys to bring up the very-excellent LaunchBar, then 'CL' or 'CR' to run whichever one I need.

Comments (5)

  • Choose Identity

  • Give eProps (?)

  • New! You can now edit your comments for 15 minutes after submitting.

About this Entry

Who recommended?

Who gave the eProps?