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


Click here to return to the 'Saving and Restoring Tabs in Safari - Documented and Improved' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Saving and Restoring Tabs in Safari - Documented and Improved
Authored by: ehouwink on Jun 28, '05 05:31:32AM
The "restore" script that adheres to this prefs-file location is:


tell application "Safari" to activate

-- Ask user for  file where Tabs were stored
set prefs_folder to (path to preferences folder as string) & "Safari:"
set prefs_fold to prefs_folder & "Saved Tabs:"
set choices to {}
tell application "Finder"
	set lizt to list folder prefs_fold
	if lizt is not "" then
		repeat with i from 1 to number of items in lizt
			if ".DS" is not in item i of lizt then ¬
				set choices to choices & item i of lizt
		end repeat
	end if
end tell
tell application "Safari" to set tFile to (choose from list choices default items (item 1 of choices) ¬
	OK button name "Get these" cancel button name ¬
	"Cancel" without multiple selections allowed)
set tFile to prefs_fold & text items of tFile as string


--try
-- read the saved urls
set open_file to ¬
	open for access alias tFile without write permission
set url_list to read alias tFile using delimiter return
close access open_file

set tmpList to {}
set newUrl_list to {}

-- make urls from file into a list of lists
-- each window is a seperate list in the big list
repeat with aUrl in url_list
	if aUrl & "x" is "x" then
		set newUrl_list to newUrl_list & {tmpList}
		set tmpList to {}
	else
		set tmpList to tmpList & aUrl
	end if
end repeat

-- don't forget the last list, or maybe the only
set newUrl_list to newUrl_list & {tmpList}

tell application "Safari"
	-- loop through the list of windows
	repeat with urls in newUrl_list
		my new_window()
		set emptyWindow to true
		-- loop through the list of tabs
		repeat with aUrl in urls
			if emptyWindow then
				set emptyWindow to false
			else
				my new_tab()
			end if
			-- open the url
			set URL of document 1 to aUrl
		end repeat
	end repeat
end tell
--on error
try
	close access file prefs_file
end try
--end try

-- let the user know we are done.
tell application "Safari"
	activate
	display dialog "All Done !" buttons {"OK"} default button 1
end tell

on new_tab()
	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 new_tab

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


[ Reply to This | # ]