Close Unselected Tabs in Safari...
Close Unselected Tabs in Safari...
- Subject: Close Unselected Tabs in Safari...
- From: David Crowe <email@hidden>
- Date: Thu, 23 Oct 2008 12:09:20 -0600
Title: Close Unselected Tabs in
Safari...
Do you get frustrated because
you end up with far too many tabs open, but you don't want to close
them all?
This script, which only works
with Safari (but probably could be adapted quite easily to Firefox)
will present you with a list of tabs in the frontmost window and you
select the ones you want to keep open.
This is only really useful if
you have an application to tie the script to a hot key. I use
FastScripts, but I know there are others. Even QuicKeys can handle an
AppleScript.
- David Crowe
--
-- Close Unselected
Tabs
--
-- Prompts the user with
a list of tabs open in the frontmost Safari window.
-- The user selects one
or more tabs to KEEP OPEN (this is because if you have a lot of tabs
open the chances are that you want more closed than left
open)
-- The UN-selected tabs
are then closed.
--
-- David Crowe,
2008.
tell application "Safari"
try
set
theTabList
to name of every tab of
window 1
on
error
errmsg
tell
me
activate
display
dialog "Quitting
because " &
errmsg giving up
after 1
end
tell
end
try
end
tell
activate
set theSelectedList to choose from list theTabList
with prompt "Select
tabs to keep open..."
with title "Select
Tabs"
with multiple
selections allowed
if theSelectedList = false
then -- User cancelled
return
end if
tell application "Safari"
set
theCloseList
to {}
repeat with anOpenTab in every tab
of window 1
set
tabSelected
to false
try
-- Tabs with an error
(e.g. page not found) don't have a name, so they can be
closed.
repeat
with
aSelectedTab
in
theSelectedList
if
aSelectedTab
as string = (name
of
anOpenTab) as string
then
set
tabSelected
to true
exit
repeat
end
if
end
repeat
end
try
if
not
tabSelected
then
try
set end
of
theCloseList
to (name of
anOpenTab) as string
on
error
errmsg number errnum
tell
me
activate
display
dialog "Cannot close "
& (name of anOpenTab)
as string
end
tell
end
try
end
if
end repeat
repeat
with
aTabName
in
theCloseList
try
close (every tab
of window 1 whose name
is
aTabName)
on
error
errmsg
tell
me
activate
display
dialog "Cannot close
tab: " &
aTabName giving up
after 3
end
tell
end
try
end
repeat
end tell
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden