I tried to write an AppleScript code to control a music sheet application iReal Pro to create sheets automatically, but I tried so many ways and I still can't get the application UI elements exactly,so then I try to record my hand operations in Automator and convert them into AppleScript codes, the strange thing is, the codes converted don't work, the original recording works, It's pretty annoying, is there any other way to finish my work?
The code I got from Animator is:
on run {input, parameters}
-- Click the “<fill in title>” button.
delay 1.812390
set timeoutSeconds to 2.000000
set uiScript to "click UI Element 1 of combo box 3 of window \"Editor\" of application process \"iReal Pro\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Blank
delay 1.351690
set timeoutSeconds to 2.000000
set uiScript to "click menu item \"Blank\" of menu 1 of window 1 of application process \"iReal Pro\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Click the “<fill in title>” button.
delay 1.812390
set timeoutSeconds to 2.000000
set uiScript to "click UI Element 1 of combo box 3 of window \"Editor\" of application process \"iReal Pro\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Type “D” into the text field.
delay 1.804798
set timeoutSeconds to 2.000000
set uiScript to "click text field 4 of list 1 of scroll area 1 of combo box 3 of window \"Editor\" of application process \"iReal Pro\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Click the “Save” button.
delay 3.115939
set timeoutSeconds to 2.000000
set uiScript to "click UI Element \"Save\" of window \"Editor\" of application process \"iReal Pro\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Click the “Close” button.
delay 0.721698
set timeoutSeconds to 2.000000
set uiScript to "click UI Element \"Close\" of window \"Editor\" of application process \"iReal Pro\""
my doWithTimeout( uiScript, timeoutSeconds )
return input
end run
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
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