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

Save open tabs in Safari into a bookmarks folder Web Browsers
I, like others, have always wanted to save the open tabs in Safari as a set of bookmarked sites. One reason is when I have no choice but to quit Safari, but have not finished with all the pages in the tabs and so lose them. Looking around, I came across this hint to do just that. However, it did not work me for a couple of reasons, one being how the script has to get to the Bookmarks' scroll area to paste the urls. To overcome this problem, I discovered that if you hit the Back and Forward buttons, the scroll area is always selected. So I used this trick to get there. The other problem was the way the tabs where counted and checked for repeats and then listed -- the original script did not do any of this as well as I would have liked.

So I rewrote the script to simplify it, as well as address these issues. The script uses GUI scripting, so make sure you have that activated (it's the 'Allow access for assistive devices' checkbox in the Universal Access System Preferences panel). As usaual, I will use Spark to run mine, but you can also put the complied script in your Safari AppleScript menu, or use another launching method of choice.

[robg adds: I tested this via a Butler AppleScript action and hotkey. At first, it didn't seem to work quite right, as I wasn't getting anything bookmarked and the bookmark folder's name was incorrect. I did a bit of testing, and got it to work by adding a delay 1 line, immediately below the set theDate to (current date) as string line in the script. I was also losing the initial "S" in the keystroke "Saved Tabs line, so I simply doubled it (SSaved Tabs).

Note that these issues are quirks of my method of implementation via Butler, as I had no such issues running the raw script directly from Script Editor. As such, I haven't put my changes into the source. Once I made my tweaks, everything worked great -- I can now save open tabs by hitting Command-Option-S in Safari.]
    •    
  • Currently 1.50 / 5
  You rated: 2 / 5 (4 votes cast)
 
[20,168 views]  

Save open tabs in Safari into a bookmarks folder | 12 comments | Create New Account
Click here to return to the 'Save open tabs in Safari into a bookmarks folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Save open tabs in Safari into a bookmarks folder
Authored by: jump420 on Nov 30, '05 08:05:28AM

great script. thank you!
works just as described.



[ Reply to This | # ]
Save open tabs in Safari into a bookmarks folder
Authored by: dogboy on Nov 30, '05 08:28:04AM
Or you could use Safari Stand (free) and Saft (shareware, $12), both available Here. Stand will let you save snapshots of tabs (like Omniweb) amongst other cool stuff (thumnail tabs? Oh yes!) Saft will save the open tabs automatically on quit, reopening them on relaunch. It will do this even through a crach or force quit (and in this case, gives the option of disabling tabs, as you usually know which one caused the crash)

[ Reply to This | # ]
Save open tabs in Safari into a bookmarks folder
Authored by: stephen.m on Nov 30, '05 08:47:35AM

With Saft, you can also save the current browser window (including all tabs) for reloading at will. For example, I visit half a dozen news sites daily; a couple of menubar clicks opens a new window and loads all six tabs.



[ Reply to This | # ]
Save open tabs in Safari into a bookmarks folder
Authored by: graemeaustin on Nov 30, '05 09:18:51AM

Yes, I'm a big fan of Saft too. It means I can switch off my laptop and come back to my browsing at the same place the following morning.

Also, Saft gives me a reminder if I accidentally close the Safari window when I've got loads of tabs open (when I really meant to close a single tab). And, you can move the order of the tabs too.

And a bunch of other stuff...

Graeme



[ Reply to This | # ]
Save open tabs in Safari into a bookmarks folder
Authored by: jimhoyt on Nov 30, '05 09:57:40AM

Saft is a real lifesaver when the occasional Safari crash occurs. It's absolutely loaded with features. I discovered the other day whilst rearranging tabs on a window that dragging a tab to a different window moves it to that window. How wonderfully unexpected and so very Mac!



[ Reply to This | # ]
Save open tabs in Safari into a bookmarks folder
Authored by: xSmurf on Nov 30, '05 10:09:03AM

I love Safari Stand, although I have noticed it will crash Safari now and then so I had to remove it. I'll give this hit a try...

---
SnitchCTL : http://snitchctl.smurfturf.net/

PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf



[ Reply to This | # ]
Save open tabs in Safari into a bookmarks folder
Authored by: Bobson on Dec 06, '05 01:33:59PM
(and in this case, gives the option of disabling tabs, as you usually know which one caused the crash)
You can have it just reload select tabs? At best, I've only seen "All" or "None"...

[ Reply to This | # ]
New crash protection in Saft
Authored by: sjk on Dec 12, '05 10:48:37AM
The New crash protection in Saft screenshot shows the ability to (de)select which tabs/windows to load.

[ Reply to This | # ]
Script modifications
Authored by: Lou Kash on Nov 30, '05 10:03:43AM
For Stand users this script is not necessary indeed, but nevertheless I have modified some portions of the script to make it work on international systems, at least on Panther (I don't know if the menu ids have changed in Safari 2).



set bigList to {}
property windowMenu : "Window"
property nextTabMenuItem : "Select Next Tab"
-- property AddBookmarkFolder : "Add Bookmark Folder" -- doesn't work on localized systems!
-- property AddBookmarkFolder : "Lesezeichen-Ordner hinzufügen" -- works on German systems (added by Lou Kash)
-- try the ID:
property AddBookmarkFolder : 4 -- tested on Panther, Safari 1.3.1 (added by Lou Kash)
-- property Bookmarks : "Bookmarks" -- doesn't work on localized systems!
-- property Bookmarks : "Lesezeichen" -- works on German systems (added by Lou Kash)
-- try the ID:
property Bookmarks : 7 -- tested on Panther, Safari 1.3.1 (added by Lou Kash)
property newbookmark : "New Bookmark"
property cut : "x"
property paste : "v"
set lastUrl to ""
set firstUrl to ""
tell application "Safari"
	activate
	set firstUrl to URL of document 1
	repeat until firstUrl is equal to lastUrl
		
		tell application "System Events"
			tell process "Safari"
				keystroke (ASCII character 29) using [command down, shift down]
				tell application "Safari"
					copy URL of document 1 to end of bigList
					set lastUrl to URL of document 1
					
				end tell
			end tell
		end tell
	end repeat
end tell

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 - <current date>"
			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
			keystroke "[" using {command down}
			keystroke "]" using {command down}
			keystroke cut using {command down}
			*)
			
			-- ... wait two seconds and then enter a tabulator character... :-) (added by Lou Kash)
			delay 2
			keystroke (ASCII character 9)
			delay 1
			
		end tell
	end tell
end tell
tell application "Safari"
	set the counter to 0
	set the item_counter to count of the the bigList
	repeat item_counter times
		
		set counter to counter + 1
		set this_URL to item counter of the bigList
		-- use a try statement to avoid undefined error
		try
			set the clipboard to this_URL
			if (this_URL is not equal to "bookmarks://") then
				tell application "System Events"
					tell process "Safari"
						keystroke paste using {command down}
					end tell
				end tell
			end if
		end try
		delay 1 --  added by Lou Kash	
	end repeat
end tell



[ Reply to This | # ]
Script modifications
Authored by: mark hunte on Nov 30, '05 11:00:07AM

eystroke (ASCII character 9)

God You know I swear I tried tabbing over but could not get it to do so. So did not try
it in the script. Oh well .

I have another one of these scripts I writing up, so that saves it having one more
Kludge.

Also thank everyone else for the comments on the other apps.
For me I do not like to load to many third party apps on the back end of my Apple apps.

---
mh



[ Reply to This | # ]
Save open tabs in Safari into a bookmarks folder
Authored by: Anonymous on Nov 30, '05 06:53:35PM
The script didnt quite work for me as expected - it would stop on this line :

click menu item AddBookmarkFolder of menu Bookmarks of menu bar 1
I tried using the ID's mentioned in one of the posts above - but that didnt quite work either... So I ended up using the keyboard shortcut to create a book mark folder. In case you are having a similar issue, try replacing this line with :

keystroke "N" using [shift down, command down]


[ Reply to This | # ]
Menu IDs
Authored by: Lou Kash on Dec 01, '05 06:22:12AM

If you use Tiger, it's possible that Safari 2 has additional menu items for adding RSS feeds; I don't know. In that case it's likely that an ID doesn't work anymore.

You can check what menu items are being selected if you run the script from the Script Editor window while having the Event Protocol tab or window open.

You might have noticed that I have used ID 4 for the AddBookmarkFolder variable. Funny though that the item "Add Bookmark Folder" is the third *visible* entry in the Bookmarks menu, thus there must be an invisible item above.
In fact, the "Show Bookmarks" item are two items in one space. "Hide Bookmarks" (if Bookmarks are visible) has ID 1 whereas "Show Bookmarks" has ID 2.
Separators are menu items as well, by the way.



[ Reply to This | # ]