Help with a "Retry Button" if error in Repeat List

I am very new to applescripting so apologies if this is fairly obvious. I have spent house looking for a solution and finally have decided to post to see if anyone can help me.

Basically I am running a simple repeat loop that runs shell commands to SSH into network’d machines to quit a program before opening the program on the local machine (I have used Firefox as an example below). What I want to do is have the script run through each item in the list [the ip addresses of the different machines] and alert me when it could not connect / errors for some reason (FYI, I have setup passwordless logins for SSH). To control what to do, I want to display dialog with three button options: Cancel (cancel out completely and stop script), OK (basically ignore connection issue/error and continue with next item in repeat loop) and Retry (which retries the current item in the repeat loop again to see if it works). I want this Retry to keep occurring until either it is successful or the user moves on by clicking the OK button.

My issue how to properly script the repeat where it retries or continues on. I know the last part of the script is wrong (and doesnt work as intended) hence why i need help.

Much thanks for any help. I know this script is probably ugly and bulky so additional comments on that are much appreciated so i can learn. Here is what i have so far:


--Read preferences from plist file
tell application "System Events"
	set plistFile to "~/Desktop/NewTest.app/Contents/com.NewTest.plist"
	set ProgBarType to (value of property list item "ProgressBarType" of property list file plistFile)
	set ipAddressOne to (value of property list item "Computer1" of property list file plistFile)
	set ipAddressTwo to (value of property list item "Computer2" of property list file plistFile)
	set ipAddressThree to (value of property list item "Computer3" of property list file plistFile)
	set ipAddressFour to (value of property list item "Computer4" of property list file plistFile)
end tell

--Set IP Addresses of machines to SSH into and close Firefox on those machines across the network.
set ipAddressList to {ipAddressOne, ipAddressTwo, ipAddressThree, ipAddressFour}
set sshList to {}

repeat with i from 1 to (length of ipAddressList)
	set checkIpAddress to item i of ipAddressList
	if {checkIpAddress} is not {""} then
		set end of sshList to checkIpAddress
	end if
end repeat

repeat with theIpAddress from 1 to (length of sshList)
	set sshLogin to item theIpAddress of sshList
	set theCommand to "ssh -o ConnectTimeout=15 " & sshLogin & " \"osascript -e 'tell application \\\"Firefox\\\" to quit'\""
	try
		do shell script theCommand
	on error
		set decision to display dialog "There was an issue connecting to " & sshLogin & ". Please check your connection and settings. Do you wish to continue without retrying?" buttons {"Cancel", "Retry", "Yes"} cancel button "Cancel" default button "Retry" with icon (note) with title {"Connection Check Warning"}
		log decision
		set decision to button returned of decision
		if decision is not "Retry" then
			exit repeat
		end if
	end try
end repeat

delay 5

tell application "Firefox" to activate

--More script

AppleScript: 2.1.2
Browser: Safari 533.18.5
Operating System: Mac OS X (10.6)

Hi,

add an extra repeat loop. If the user presses “Yes”, the (inner) repeat loop will be exited and the script executes the next iteration of the outer repeat loop. “Retry” repeats the current iteration and “Cancel” aborts the script anyway


repeat with theIpAddress from 1 to (length of sshList)
	repeat
		set sshLogin to item theIpAddress of sshList
		set theCommand to "ssh -o ConnectTimeout=15 " & sshLogin & " \"osascript -e 'tell application \\\"Firefox\\\" to quit'\""
		try
			do shell script theCommand
		on error
			set {button returned:decision} to display dialog "There was an issue connecting to " & sshLogin & ". Please check your connection and settings. Do you wish to continue without retrying?" buttons {"Cancel", "Retry", "Yes"} cancel button "Cancel" default button "Retry" with icon (note) with title {"Connection Check Warning"}
			log decision
			if decision is "Yes" then exit repeat
		end try
	end repeat
end repeat

Sigh…

That was too easy i suppose and I had thought an inner repeat loop might be needed but couldnt figure it out.

Thanks stefan. It worked.

Actually spoke to soon. Now that i got home to try it problem is when the SSH errors everything works fine but if the SSH is successful, there is nothing to get the script out of the inner repeat loop. Keeps trying the same do shell script over and over…Tried a few things and could not get it to work.

Any additional thoughts appreciated.

Edit: Nevermind. I figured it out. I just added a

if result is ("") then exit repeat

after the shell script.

Thanks.