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


Click here to return to the 'Restore Tabs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Restore Tabs
Authored by: luai on May 18, '05 11:03:51PM

There were two nice scripts called: (Saving Session & Restoring Session).
They work very well under panther bun not anymore with tiger.
I don't remember their origin, but they were really helpful. you can save ALL your windows and tabs for a later session-hence the name.
I am posting the text of these scripts, so as any Scrip guru can help modifying them to work in Tiger.
Saving session:

-- localizations
property windowMenu : "Window"
property nextTabMenuItem : "Select Next Tab"
-- end localizations

property url_list : {}
property docCount : 0


tell application "Safari"
activate
set docCount to count of documents
end tell

tell application "System Events"
tell process "Safari"

set menuItemCount to count of menu items of menu windowMenu of
menu bar 1
set menuItemOffset to menuItemCount - docCount

set url_list to {}

-- count the windows
set winCount to count of windows

-- loop through the windows
repeat with k from 1 to winCount

set winNum to k

set winTitle to title of window winNum

-- a bit nasty, but the front window is always number 1
set winNum to 1

if (count of characters of winTitle) > 20 then
set winTitle to text 1 thru 20 of winTitle
end if

repeat with j from menuItemOffset + 1 to menuItemCount
if ((title of menu item j of menu windowMenu of menu bar 1)
starts with winTitle) then
set itemNum to j
exit repeat
end if
end repeat

-- activate a window
click menu item itemNum of menu windowMenu of menu bar 1

set firstUrl to ""

-- check for browser window
if (count of radio buttons of window winNum) > 0 then

-- activate the first tab
click radio button 1 of window winNum

-- url of first tab
set firstUrl to value of text field 1 of group 1
of splitter group 1 of window winNum

-- save the url
set url_list to url_list & firstUrl

my nextTab()

-- url of the next tab
set nextUrl to value of text field 1 of group 1
of splitter group 1 of window winNum

repeat until firstUrl is equal to nextUrl

-- save the last url
set url_list to url_list & nextUrl

my nextTab()

-- url of next tab
set nextUrl to value of text field 1 of group 1
of splitter group 1 of window winNum

end repeat

-- empty line to seprate windows
set url_list to url_list & ""

end if

end repeat
end tell
end tell

-- convert url list to text
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set url_list_text to url_list as text
set AppleScript's text item delimiters to old_delim

-- get path to prefs file where URLs will be stored
set prefs_folder to path to preferences folder as string
set prefs_file to prefs_folder & "Safari Saved URLs"

try
set open_file to
open for access file prefs_file with write permission
-- erase current contents of file:
set eof of open_file to 0
write url_list_text to open_file starting at eof
close access open_file
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 nextTab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
click menu item nextTabMenuItem of
menu windowMenu of menu bar 1
end tell
end tell
end nextTab

Restoring Session:

tell application "Safari" to activate

-- get path to prefs file where URLs are stored
set prefs_folder to path to preferences folder as string
set prefs_file to prefs_folder & "Safari Saved URLs"

try
-- read the saved urls
set open_file to
open for access file prefs_file without write permission
set url_list to read open_file 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 | # ]
Restore Tabs
Authored by: kadis on May 18, '05 11:24:09PM
I believe it may be from Daring Fireball: Save and Restore Safari URLs < http://daringfireball.net/2003/02/save_and_restore_safari_urls >

[ Reply to This | # ]
saving/restoring tabs
Authored by: sjk on May 19, '05 11:50:04PM

And there've been several variations of the script posted here on MacOSXHints. Shortcomings aside, Saft's method of saving/restoring tabs was the most reliable for me.



[ Reply to This | # ]