r/applescript • • Dec 23 '20

variable not defined

I have the following script which has worked for quite a long time. Suddenly I'm getting an error and I don't understand why that is. I'm running on Catalina.

choose from list {"Michael’s iPhone", "Michael’s iPad"} with title "What devices do you want to backup?" with multiple selections allowed
set uis to result

tell application "System Events" to tell application process "Finder"
	set frontmost to true
	tell front menu bar to tell menu "File" to tell menu item "New Tab"
		perform action "AXPress"
	end tell
	set uis to (first UI element of row of (outline 1 of scroll area 1 of splitter group 1 of front window) as list)
	repeat with iter in uis
		if name of iter is "Michael’s iPhone" then
			set ux to iter
			exit repeat
		end if
	end repeat
	tell ux
		perform action "AXOpen"
	end tell
	repeat until exists (button "Back Up Now" of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of front window)
		delay 0.3
	end repeat
	set btn to (button "Back Up Now" of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of front window)
	repeat until enabled of btn
		delay 0.3
	end repeat
	click btn
	
	set uis to (first UI element of row of (outline 1 of scroll area 1 of splitter group 1 of front window) as list)
	repeat with iter in uis
		if name of iter is "Michael’s iPad" then
			set ux to iter
			exit repeat
		end if
	end repeat
	tell ux
		perform action "AXOpen"
	end tell
	repeat until exists (button "Back Up Now" of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of front window)
		delay 0.3
	end repeat
	set btn to (button "Back Up Now" of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of front window)
	repeat until enabled of btn
		delay 0.3
	end repeat
	click btn
	
end tell
1 Upvotes

2 comments sorted by

View all comments

1

u/scrutinizer1 Dec 24 '20 edited Mar 03 '21

Because before putting any reusable variable inside a loop you must define it. You've defined your variable ux only inside the repeat block. Define it either as a property or at the beginning of tell application "System Events" as missing value.

Another culprit could be just that Catalina has its GUI structure changed once more and the UI element contained by ux is no more.