Update Camino to latest nightly without losing open tab URLs.

-- "This script gets the URLs on each of the open tabs in a single Camino window, then calls CaminoKnight to update to the latest nightly build of Camino if there is one, repopulating the saved tabs in a new window of the latest nightly or the current version of Camino iif there isn't a new nightly."
-- "The script requires that CaminoKnight is set to Auto Start and to Quit when done, but NOT to launch Camino again (the middle check box) - that is done by the script."

set theTabs to getTabs()

tell application "CaminoKnight"
	activate
	delay 5 -- wait for CK to open rather than testing for it. 
	-- Note: this is a weakness in this script. If CaminoKnight has trouble connecting (i.e. takes more than 5 seconds and your version of Camino is current so a dialog is coming),  the script will still move on. If a dialog is posted after 5 seconds, then either the user has to click "Quit" or we wait for CK to quit by itself (20 seconds). Either way, when it quits, we reopen the tabs.
	
	-- Test to see if there is a dialog box -- meaning no new nightly yet -- then dismiss the dialog (with the default "Quit" button). Key Code 76 is "Enter" {keystroke (ASCII character 3) doesn't seem to work on this dialog}.
	
	if (name of window 1 is "dialog1") then
		tell application "System Events" to key code 76 -- dismiss the dialog
		my openTabs(theTabs)
		return -- we're done
	end if
end tell

-- If there is no dialog box, wait for CaminoKnight to install the new nightly over the older version (CK quits the old Camino itself). CK quits itself automatically (set in its preferences to do so). Restart Camino with the saved tabs when CK quits.

tell application "System Events"
	repeat
		if exists process "CaminoKnight" then
			delay 2
		else
			exit repeat
		end if
	end repeat
end tell
delay 3

openTabs(theTabs)

to getTabs()
	set TabURLs to {}
	tell application "Camino"
		activate
		-- get the tab URLs. Camino is not very scriptable. There is no way to find out how many tabs are open, for example, so getting the URL of the front window returns the URL of whichever tab has focus and the only way to get them all is to close them. Eventually that closes the window and the repeat loop errors out.
		repeat
			try
				set aURL to URL of front window
				tell application "System Events" to keystroke "w" using {command down}
				if aURL is not in TabURLs then set end of TabURLs to aURL
			on error -- No more tabs to get when Cmd-w has closed Camino's window.
				exit repeat
			end try
		end repeat
	end tell
	return TabURLs
end getTabs

to openTabs(tabList)
	tell application "Camino" to activate
	if (count of tabList) = 0 then return
	set tabCount to count of tabList
	repeat with k from 1 to tabCount
		open location (item k of tabList)
	end repeat
end openTabs