Applescript looping and error messages

Evening All,

I have an applescript (it was an automater script that was then automagically converted to applescript) that does what it is suppose to do except for two small niggles.

I’m not a programmer at all (the last programming was C# MANY years ago!

Here is the script:

– Click the “In Tray” URL.
set uiScript to “click static text 1 of UI Element "In Tray" of group 23 of UI Element 1 of scroll area 1 of group 3 of window "OrderWork: Service Partner Work Order Listing" of application process "Safari"”
my doWithTimeout(uiScript)

– Click the text “20110403918”
set uiScript to “click static text 1 of UI Element 1 of row 2 of table 1 of UI Element 1 of scroll area 1 of group 3 of window "OrderWork: Service Partner Work Order Listing" of application process "Safari"”
my doWithTimeout(uiScript)

– Click the text " Accept"
set uiScript to “click static text 1 of group 1 of UI Element 58 of UI Element 1 of scroll area 1 of group 3 of window "OrderWork: Service Partner Work Order Detail" of application process "Safari"”
my doWithTimeout(uiScript)

– Click the " Accept" URL.
set uiScript to “click static text 1 of UI Element " Accept" of group 70 of UI Element 1 of scroll area 1 of group 3 of window "OrderWork: Work Order Accept" of application process "Safari"”
my doWithTimeout(uiScript)

– Click the text " Finish"
set uiScript to “click static text 1 of group 1 of UI Element 62 of UI Element 1 of scroll area 1 of group 3 of window "OrderWork: Work Order Accept" of application process "Safari"”
my doWithTimeout(uiScript)

– Main calling script
on doWithTimeout(uiScript)
set endDate to (current date) + 2 – 2 second timeout value
repeat
try
run script “tell application "System Events"
" & uiScript & "
end tell”
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout

As you can see it is 5 subroutines that are called by the main calling script. What I need help with is…

  1. If a routine faults then an error message is raised and execution stops. If I remove the following lines then it simply hangs as it doesn’t know what to do. How can I get it to continue to run after an error condition?

if ((current date) > endDate) then
error "Can not " & uiScript
end if

  1. How can I get the whole thing to continually loop ad infinitum?

Model: Macbookpro
AppleScript: Latest
Browser: Safari 533.21.1
Operating System: Mac OS X (10.6)

The error command stops the script. Change the error to a simple display alert like

display alert “ERROR:” message errorMessage

Now the script will not stop but only show an alert. When the alert is closed the code will continue with it’s repeat loop.

Okay, that suggestion works - thank you very much!

Last wee bit then - how to get the whole thing to loop forever?

remove the line ‘exit repeat’ I overlooked that line. that line will stop the loop if it was succesfull.