hi -
I use a script that saves and then opens your saved tabs for safari acquired it originaly from MacOSX Hints until i upgraded to panther. now it no longer works properly.
the problem is occurring when saving tabs for the 2nd time or more. the script is supposed to be clearing the contents of a text file where the url’s are saved… however in panther it is not… the script just keeps adding the urls to the end of it or not being overwritten… i have encountered both.
this is the section of code that seems to be the problem:
– erase current contents of file:
set eof of open_file to 0
write url_list to open_file starting at eof
close access open_file
this is the “save tabs” script:
– 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
– count the windows
set winCount to count of windows
– loop through the windows
repeat with i from 1 to winCount
set winTitle to title of window i
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
– check for browser window
if (count of radio buttons of window i) > 0 then
– activate the first tab
click radio button 1 of window i
– url of first tab
set firstUrl to value of text field 1 of group 1 ¬
of splitter group 1 of window i
– 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 i
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 i
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 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 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
this is the “open tabs” script:
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
can anyone help me straighten this out?
Thanks.