Applescript Throws Error on AXPress

The script runs a product export from LightSpeed POS every night, except it’s now broken. It worked for more than two years.


on ShtWait(ProcName, WndwName, btnName, DelayTime)
	do shell script "logger -t 'EXPORT-PRODUCTS' 'Sheet Wait '" & WndwName & " Button " & btnName
	log "Sheet Wait " & btnName
	tell application "System Events"
		tell application process ProcName
			set ShtFound to false
			repeat while ShtFound is false
				if button btnName of sheet of window WndwName exists then
					set ShtFound to true
				end if
				log DelayTime & " second delay"
				delay DelayTime
			end repeat
		end tell
	end tell
end ShtWait


	tell application "System Events"
		tell application process ProcName	
			tell button btnName of sheet of window WndwName
				perform action "AXPress"
			end tell
		end tell
	end tell

The Reply is
tell application “System Events”
exists button “Replace” of sheet of window “Save Export” of application process “Lightspeed”
→ true
(1, second delay)
perform action “AXPress” of button “Replace” of sheet of window “Save Export” of application process “Lightspeed”
→ error number -1708
Result:
error “System Events got an error: action "AXPress" of button "Replace" of sheet of window "Save Export" of application process "Lightspeed" doesn’t understand the “perform” message.” number -1708 from action “AXPress” of button “Replace” of sheet of window “Save Export” of application process “Lightspeed”

So the button exists, but I can’t press it.

I use the same basic procedure several times in this script, and it continues to work. The only obvious difference is the

button Y of sheet of window X

In every other case, it’s

button Y of window X


on BtnClick(ProcName, WndwName, btnName)
	do shell script "logger -t 'EXPORT-PRODUCTS' 'ButtonClick '" & WndwName & " Button " & btnName
	log "Button Click " & WndwName & " " & btnName
	set DelayTime to 3
	set btnFound to false
	tell application "System Events"
		tell application process ProcName
			repeat while btnFound is false
				if button btnName of window WndwName exists then
					log "Delay " & DelayTime & " to check button " & btnName & " again, then press"
					set btnFound to true
					delay DelayTime
					tell button btnName of window WndwName
						perform action "AXPress"
					end tell
				end if
			end repeat
		end tell
	end tell
end BtnClick

Unfortunately, it takes over an hour to run the export, and I don’t know how to otherwise get that

button of sheet of window

This worked up until the upgrade to El Capitan. I don’t know what changes occurred. I know it broke some other folk’s scripts. I find that logging to the console usually helps me with debugging.

Any ideas?

Hi.

Since sheets are elements of windows, not properties, the first thing to try would be include some indication of which sheet you mean ” even if there’s only one:

button Y of sheet 1 of window X

I can see that ‘sheet of window WndwName’ apparently works in your script when testing for the button’s existence, but it’s best to make sure the syntax is correct before thinking about other possible reasons for the click failure.

It seems crazy to me, but this has been crazy since it broke.

perform action AXPress

stopped working. I originally used AXPress because Click didn’t work. Now Click works fine, and AXPress doesn’t.

			tell button btnName of sheet of window WndwName
				perform action "AXPress"
			end tell

just became


Click button btnName of sheet of window WndwName

and it works.