Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Improved! 'Faster', less fragile, drops empty tabs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Improved! 'Faster', less fragile, drops empty tabs
Authored by: ageless on Apr 08, '04 08:50:00PM
Here's a revision of djrc's revision.

The main difference is that the active window is preserved, which is helpful if you first select a window with a lot of tabs or with tabs that shouldn't (or can't) be reloaded. If you have one window with 8 tabs and three other windows with only one tab, then this revision will be much faster!

The other cool thing is that this revision will drop empty tabs, as well as empty windows.

Since this builds on djrc's, you don't need to have the tab bar set to always show.

There are a few other features I'm trying to add:

-- Need to fix so that tabs with alert dialogs (like "Server not found") won't mess everything up. (Update: Fixed!)

-- Automatically preserve window with greatest number of tabs.

-- Set script to trigger when a page is opened in a new window

I'm also looking to spruce up mazatty's save/restore scripts (see comment above), so that the save script can handle empty tabs and alert dialogs (I think it chokes on both).

***UPDATE***

I fixed it so that it will dismiss the "server not found" alert dialog and drop the corresponding window or tab!

It may have problems with javascript alerts, I haven't tested it yet. And better error checking would be nice (instead of just messing things up). Anyone?


set url_list to {}

tell application "System Events"
	tell process "Safari"
		
		-- count the windows
		set winCount to count of windows
		
		-- loop through the windows, except for the active one
		repeat with i from 2 to winCount
			
			-- count the tabs
			set tabCount to count of radio buttons of window i
			
			--- if there are tabs:
			if tabCount > 0 then
				
				-- loop through the tabs
				repeat with j from 1 to tabCount
					-- activate the tab 
					click radio button j of window i
					
					-- dismiss a possible alert dialog
					if exists sheet 1 of window i then
						
						tell sheet 1 of window i
							click button "OK"
						end tell
						
					else
						
						-- url of window
						set theUrl to value of text field 1 of group 1 
							of splitter group 1 of window i
						
						if theUrl is not equal to "" then
							
							-- save the url
							set url_list to url_list & theUrl
							
						end if
					end if
				end repeat
				
				--- if no tabs: 
			else
				-- just add the url of the window
				
				-- dismiss a possible alert dialog
				if exists sheet 1 of window i then
					
					tell sheet 1 of window i
						click button "OK"
					end tell
					
				else
					
					set theUrl to value of text field 1 of group 1 
						of splitter group 1 of window i
					
					if theUrl is not equal to "" then
						
						-- save the url
						set url_list to url_list & theUrl
						
					end if
				end if
			end if
		end repeat
	end tell
end tell


tell application "Safari"
	(* Close all windows other windows *)
	repeat with i from 2 to winCount
		close window 2
	end repeat
	
	(* Open all urls in the active window *)
	repeat with aUrl in url_list
		my newTab()
		set the URL of document 1 to aUrl
	end repeat
end tell



on newTab()
	tell application "Safari" to activate
	tell application "System Events"
		tell process "Safari"
			click menu item "New Tab" of menu "File" of menu bar 1
		end tell
	end tell
end newTab


[ Reply to This | # ]
Improved! 'Faster', less fragile, drops empty tabs
Authored by: ceesaxp on Apr 12, '04 04:02:10PM

I wish there was a way to do it without reloading each URL in newly created tabs... Wait, don't say "Camino" -- I want a way to do that in Safari...



[ Reply to This | # ]