1

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
red_menace
  • 3,162
  • 2
  • 10
  • 18
BrotherYao
  • 79
  • 4
  • Does the app have a scripting dictionary, and what are you getting from Automator? – red_menace Nov 05 '19 at 03:06
  • Yes, the app has a scripting dictionary, but there is no way to know how to create a new document with the dictionary, the code I got from Automator I will paste to the question. – BrotherYao Nov 05 '19 at 04:17
  • To use in a regular AppleScript, you need to remove `{input, parameters}` and the `return input` statement from the `run` handler, since the script isn't running in an Automator workflow. – red_menace Nov 05 '19 at 04:32
  • The code works, but there is an error appears during executing the second action:Can not click UI Element 1 of combo box 3 of window "Editor" of application process "iReal Pro" – BrotherYao Nov 05 '19 at 05:43
  • I don't have the app to test, but you might need to bump up the time delay for the specific command to let things catch up. – red_menace Nov 06 '19 at 13:35

0 Answers0