Stopping AppleScript from Failing

I’ve got an AppleScript that runs every hour on a machine we use for backing up during the day. It works fine, when all machines are on or not asleep, but on some days, a worker or two may not be in. This causes the Applescript to just fail once it tries to connect to their machine. How can I stop this? I’m fairly new to AppleScript. I’m used to other languages like PHP, ASP (.NET) and other web ones but AppleScript is more of a logical “tell it as it is” language; but I can’t seem to find any proper documentation, any ideas? Thanks in advance!

Model: 24" Intel iMac 2.33GHz 2GB Ram / PowerMac G4 Dual 1.42GHz 1GB Ram / 15" PowerBook G4 Ti 1GHz 512MB Ram
Browser: Firefox 2.0.0.11 / Safari 3
Operating System: Mac OS X (10.5)

Hi,

either you detect whether the machines are available
or you use a try block to catch the error like


try
	-- do something
end try

or with error handling


try
	-- do something
on error
	-- do error handling
end try

in an error occurs, the script jumps to the end of the try block or in the second form to the on error line

Ah thanks for the quick reply. How could I see if the machine is available?

Model: 24" Intel iMac 2.33GHz 2GB Ram / PowerMac G4 Dual 1.42GHz 1GB Ram / 15" PowerBook G4 Ti 1GHz 512MB Ram
Browser: Firefox 2.0.0.11 / Safari 3
Operating System: Mac OS X (10.5)

it depends on how you connect to the machine(s)
Can you post this portion of your script?

It’s all via AFP:

tell application "Finder"
	activate	
	try
		mount volume "afp://user:pass@computer.local"
	end try
        [...]
end tell

Apple has changed some details in Leopard, so my script ro detect servers doesn’t work anymore.
The easiest way is to move the end try line, the Finder is actually not needed to mount the volume.
If you get a timeout error, because the volume is not available, it skips the rest of the code till the end try line

try
	mount volume "afp://user:pass@computer.local"
	[...]
end try

Ok, so then all I need is just a log list of tries and mounts? Is there a way I can create an array of afp:// strings and then send them into a loop where they’re tried?

this could be a way, the variable availableList will contain a list of the available servers

property devList : {"server1.local", "server2.local", "server3.local"}
property accountDataList : {"name1:pass1", "name2:pass2", "name3:pass3"}

set availableList to {}
repeat with i from 1 to count devList
	if mount_server(item i of accountDataList, item i of devList) then
		set end of availableList to item i of devList
	end if
end repeat
availableList

on mount_server(accountData, device)
	try
		mount volume "afp://" & accountData & "@" & device
		return true
	on error
		return false
	end try
end mount_server