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


Click here to return to the 'A 'Save Tabs as Bookmark Folder' script for Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A 'Save Tabs as Bookmark Folder' script for Safari
Authored by: hypert on Sep 22, '04 10:44:20PM
Same here. I've done some GUI scripting, but I can't quite figure out how else to do what the script is trying to do on this line:

click button "New Bookmark" of group 2 of splitter group 1 of scroll area 1 of group 2 of window "Bookmarks"


Also, I just put this in Script Editor, saved, and ran from there.  My Safari doesn't have the Script menu others have mentioned.  I've turned on Safari's Debug menu, but I haven't seen a Script menu.  How do I turn that on?

Thanks!</code></pre>


[ Reply to This | # ]
A 'Save Tabs as Bookmark Folder' script for Safari
Authored by: Frederico on Sep 22, '04 11:59:49PM
This script is a raging example of why GUI scripting is so terribly, horribly unreliable -- with all due respect to the author.

For example, this script as written will:

• fail if the Address bar is not visible
• fail if the Location bar is visible
• double the number of entries for each URL if the Downloads or Activity window is open
• Fail for any other number of differences in what the author and the user has set to display

I can fix a lot of this script with a lot of checks and error handling, but I'm not sure it's worth it.

To the poster directly above, and those above that, you might try swapping out this section for the original (be sure to delete the original section and replace it entirely with this:

-- 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 - <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
			delay 5
			try
				click button "New Bookmark" of group 2 of splitter group 1 of scroll area 1 of group 2 of window "Bookmarks"
			on error
				click button "New Bookmark" of group 2 of splitter group 1 of scroll area 1 of group 1 of window "Bookmarks"
			end try
			keystroke return
			keystroke "x" using {command down}
		end tell
	end tell
end tell



[ Reply to This | # ]
A 'Save Tabs as Bookmark Folder' script for Safari
Authored by: Frederico on Sep 23, '04 12:09:39AM
OK, here's a couple more fixes:


on addUrlToList()
	-- add the URL to the end of the list
	tell application "Safari"
		activate
		set newURL to the URL of document 1
		--set the end of the URL_list to the URL of document 1
		if URL_list does not contain newURL then set the end of the URL_list to newURL
	end tell
end addUrlToList

The above section will prevent multiple URLs from being added; still need to fix the script so it doesn't check every URL an extra time for every open non-browser window.


-- 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 - <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
			delay 5
			try
				click button "New Bookmark" of group 2 of splitter group 1 of scroll area 1 of group 2 of window "Bookmarks"
			on error
				try
					click button "New Bookmark" of group 2 of splitter group 1 of scroll area 1 of group 1 of window "Bookmarks"
				on error
					click button "New Bookmark" of group 2 of splitter group 1 of scroll area 1 of group 3 of window "Bookmarks"
				end try
			end try
			keystroke return
			keystroke "x" using {command down}
		end tell
	end tell
end tell

This second version of the above section should create the bookmark focus required in nearly every possible window configuration (View Location Bar on/off; view Address Bar on/off; etc.)

I still have to fix the condition where the script won't run at all if the view is not that the author tested it under.

[ Reply to This | # ]