1

AppleScript fails with -10810 on "System Events" on the first execution. The second execution works fine, if execution runs again immediately.

Code:

Behavior:

So it fails the first time on tell application "System Events" in setup.rb

execute 'login to gui' do
  command <<EOF
    osascript -e '
      tell application "System Events"
        keystroke "vagrant"
        keystroke return
        delay 3.0
        keystroke "vagrant"
        delay 3.0
        keystroke tab
        keystroke return
        keystroke return
      end tell
    '
  EOF
end

Running it again immediately gets past that and fails on tell application "System Events" in extension.rb

execute new_resource.safariextz do
  command <<EOF
    osascript -e '
    tell application "Finder" to open POSIX file "'"#{new_resource.safariextz}"'"
    delay 10
    tell application "System Events"
      tell process "Safari"
        set frontmost to true
          repeat until (exists window 1) and subrole of window 1 is "AXDialog" -- wait until the dialog is displayed.
            delay 1
          end repeat
        click button 1 of front window -- install
      end tell
    end tell
    tell application "System Events"
      if ((name of processes) contains "Safari") then
        tell application "Safari" to quit
      end if
    end tell
    '
  EOF
end

Running it immediately a third time, it gets past the second problem and completes successfully

If you wait a few minutes before running again, the behavior repeats itself all over again

Here are examples of the errors:

STDOUT: 
  STDERR: 40:59: execution error: An error of type -10810 has occurred. (-10810)
---- End output of osascript -e '
    tell application "System Events"
      keystroke "vagrant"
      keystroke return
      delay 3.0
      keystroke "vagrant"
      delay 3.0
      keystroke tab
      keystroke return
      keystroke return
    end tell  
   '   
 ----


STDOUT:
  STDERR: 66:75: execution error: An error of type -10810 has occurred. (-10810)
---- End output of osascript -e '
       tell application "System Events"
         tell process "Safari"
           set frontmost to true
             repeat until (exists window 1) and subrole of window 1 is "AXDialog" -- wait until the dialog is displayed.
        delay 1
             end repeat
           click button 1 of front window -- install
       end tell
       '
----
Dennis Hoer
  • 3,039
  • 2
  • 23
  • 34

1 Answers1

0

Try to insert a launch command after the first tell application "System Events" line. System Events quits automatically after 5 min of inactivity, that explains the "wait a few minutes" behavior

The last System Events tell block can be replaced with

if application "Safari" is running then quit application "Safari"
vadian
  • 274,689
  • 30
  • 353
  • 361
  • Thanks for the quit app tip. I tried the launch and it caused a "Application isn't running -600" error. See http://stackoverflow.com/a/24111931/4548096. – Dennis Hoer Jun 25 '15 at 21:16
  • The issue is system events app doesn't seem to run until after the chef run. Adding a delay doesn't seem to help either. – Dennis Hoer Jun 25 '15 at 23:20