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


Click here to return to the 'Updated Save script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Updated Save script
Authored by: mazatty on Oct 20, '03 11:24:07PM

it appears that the 10.2.8 update has broken the save script. i have updated this script to handle tabs that you don't see, the one you get to from the ">>" button. this update also seems to fix the problem with 10.2.8. here it is

-- 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
hope this helps. good luck.

[ Reply to This | # ]
Updated Save script
Authored by: Pierre Igot on Nov 12, '03 03:02:10PM

I thoroughly enjoyed using your Saving and restoring tabs in Safari script for Jaguar

Unfortunately, it appears that this script no longer works properly in Panther with Safari 1.1.

Any plans on an update?

TIA

Pierre

---
Pierre Igot
LATEXT - Literature & Visuals @ www.latext.com
BETALOGUE - Weblog at www.latext.com/blog/
"Apple Peel" Columnist @ Applelust.com



[ Reply to This | # ]
Updated Save script -- for Panther
Authored by: jeffschuler on Dec 07, '03 12:49:51AM
I'm trying to make this work in Panther with Safari 1.1. Using the "Updated Save script" from mazatty posted here in the comments, the first thing to change is that the two occurrences of
menu windowMenu of menu bar 1
should be changed to
menu windowMenu of menu bar item windowMenu of menu bar 1
Doing this, the script works mostly... However, something screwy is going on when saving your tabs after the first time running the script. Instead of writing over the previous file, the new URLs are tacked onto the end of the file, and returns aren't used as delimiters. Even if the file is deleted & a new one written, the old results come back from the dead... Strange. Could this have something to do with Panther's journalling?

[ Reply to This | # ]
Updated Save script -- for Panther
Authored by: sfreimark on Dec 21, '03 09:53:20AM
That doesn't work for me either. With your changes for Panther I'm getting this error: NSReceiverEvaluationScriptError: 4 Script Editor marks these two lines near the beginning of the script:

set menuItemCount to count of menu items of ¬
menu windowMenu of menu bar item windowMenu of menu bar 1
Any ideas?

[ Reply to This | # ]
Updated Save script -- for Panther
Authored by: sfreimark on Dec 21, '03 10:02:17AM

Me again. Sorry, I didn't changed the localizations at the beginning of the scripts. Now it's working - except of the same errors you are experiencing (dead URLs, no return delimiters).
Would be glad if someone could solve that problem...



[ Reply to This | # ]
Updated Save script
Authored by: snoozy on Nov 13, '03 11:54:03PM

Actually the original script works fine for me in 10.2.8, and as a lark I tried this updated script and it would not function properly. So I went back to the original script and it is back functioning just grand!

I also saved the scripts as a application to another location and placed them in the dock for quick access.

Thanks again for a fine bit of scripting.



[ Reply to This | # ]
Updated Save script
Authored by: kwaits on Jan 20, '04 02:16:23PM

I'm operatings under 10.2.8. This script DID NOT work. The script breaks down at the "my nextTab()" point following the
-- save the url
set url_list to url_list & firstUrl

command



I get the following error message: Can't make «class pcap» "Safari" of application "System Events" into the expected type.

I let others do my scripting for me, so I have no idea what this means.

But I DO need this refined script, because I want to capture LOTS of Safari tabs, including those in the >> part, and the previous script works, but only captures the tabs in active windows.

Thanks for your help. Even the old script is better than nothing.

---
kwaits



[ Reply to This | # ]