Saving the state of a Camino window and returning to it

Occasionally, you’d like to close a window full of tabs and come back to it later. This script saves a list of the URLs of each of the tabs of a Camino window so they can be opened again later. It closes each of the tabs as it runs because Camino does not support a keycode for moving among tabs.

set theTabs to {}
tell application "Camino"
	activate
	-- get the tab URLs
	repeat
		try
			set aURL to get the URL of front window
			tell application "System Events" to keystroke "w" using {command down}
			if aURL is not in theTabs then set end of theTabs to aURL
		on error -- errors when Cmd-w closes the window
			exit repeat
		end try
	end repeat
end tell

-- this opens them again given the list of tab URLs.
set tabCount to count of theTabs
tell application "Camino"
	repeat with k from 1 to tabCount
		open url (item k of theTabs)
	end repeat
end tell

Addendum: CaminoUser pointed out (note in Scripting News) that Camino does support keycodes for moving among tabs: Command-Option Right Arrow circulates to the right and Command-Option Left Arrow circulates to the left.

This can be accomplisted thus (moving to the left)

tell application "Camino"
	activate
	tell application "System Events" to keystroke (ASCII character 28) using {command down, option down}
end tell
-- and for moving to the right (ASCII character 29) replaces 28 above

Since I use the original as part of an Applescript to record my tabs, open CaminoKnight to get the latest Camino nightly build, and then repopulate the tabs, I want the error as an easy way to see that I’ve recorded all the tabs. Otherwise, I’d have to check every tab name to see if it was already in the list before stopping, and that would screw up when two tabs did have the same address for some reason.