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
'
----