-- localizations property windowMenu : "Window" property nextTabMenuItem : "Select Next Tab" property AddBookmarkFolder : "Add Bookmark Folder" property Bookmarks : "Bookmarks" -- end localizations property URL_list : {} property docCount : 0 -- much of this script generously borrowed from previous posts at -- http://www.macosxhints.com/article.php?story=20030913153245341 -- get a list of the documents tell application "Safari" activate set docCount to count of documents end tell -- iterate through each tab of window in Safari 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 my addUrlToList() my nextTab() my addUrlToList() -- 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 my nextTab() my addUrlToList() -- url of next tab set nextUrl to value of text field 1 of group 1  of splitter group 1 of window winNum end repeat end if end repeat end tell end tell -- create a new bookmark folder tell application "Safari" activate tell application "System Events" tell process "Safari" -- add bookmark folder click menu item AddBookmarkFolder of menu Bookmarks of menu bar 1 -- name the folder "Saved Tabs - " set theDate to (current date) as string keystroke "Saved Tabs - " & theDate -- hit return to name the folder keystroke return -- programming a tab will not select the bookmarks area, so have to -- create a new subfolder -- and then delete it click button "New Bookmark" of group 2 of splitter group 1 of scroll area 1 of group 2 of window "Bookmarks" keystroke return keystroke "x" using {command down} end tell end tell end tell -- Safari does some neat things when you paste a URLs while the bookmark list -- is selected. Specifically, it creates a bookmark for that URL. -- For each URL in the URLlist, paste it. tell application "Safari" repeat with j from 1 to (count of the the URL_list) set this_URL to item j of the URL_list set the clipboard to this_URL -- if the tab has the bookmarks folder open -- ignore it, as it will bookmark the bookmarks folder if (this_URL is not equal to "bookmarks://") then tell application "System Events" tell process "Safari" keystroke "v" using {command down} end tell end tell end if end repeat end tell on addUrlToList() -- add the URL to the end of the list tell application "Safari" activate set the end of the URL_list to the URL of document 1 end tell end addUrlToList 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