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)