Using applescript with Calendar in El Capitan

apple-configuratorapplescriptcalendar

I've been trying for weeks to script an ipad restore process for Apple Configurator 2. My script works fine when ran within Script Editor, and it also works as a stand alone application. The problem occurs when my script is launched from a Calendar event (which is the whole idea so I don't have to run it manually). Here is the first part of my script:

tell application "Apple Configurator 2"
activate
delay 30
tell application "System Events"
    tell process "Apple Configurator 2"
        keystroke "a" using {command down}
        delay 5
        click menu item "1 - Erase" of menu 1 of menu item "Apply" of menu 1 of menu bar item "Actions" of menu bar 1
        delay 5
        click button "Apply" of sheet 1 of window "All Devices"
    end tell
end tell

The script triggers just fine, and all is working until it attempts to click the "Apply" button. My script application returns this error:
Can't get window "All Devices" of <> "Apple Configurator 2" of application
"System Events".

System Events got an error: Can't get window "All
Devices" of process "Apple Configurator 2". (-1728)

As an Applescript newbie, I'm out of ideas. Anybody else?
Thanks!

Best Answer

Code does not work as is. I have tested this and it works.

tell application "Apple Configurator 2"
activate
delay 30
tell application "System Events"
    keystroke "a" using {command down}
    delay 5
    click menu item "1 - Erase" of menu 1 of menu item "Apply" of menu 1 of menu bar item "Actions" of menu bar 1
    delay 5
    click button "Apply" of sheet 1 of window "All Devices"
end tell
end tell