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.
Post a Comment
- Back to sean's Xanga Site!
- Note: your comment will appear in sean's local time zone: GMT -07:00 (Mountain Standard - US, Canada)


Comments (5)
U R L33T!!1!
scared o you! have a great weekend!
Now all you need is a script for a money tree and i think you could control the world..
I agree with HomerTheBrave