Pass a string as a parameter

I am scraping data from the web and my scripts get longer because of repetitions. So I want to replace some commands with a string .

The script below hopefully shows what I mean in the try block the 1st command works the second which concatenates the 1st half with the string “LastSt” does not. Have tried passing it as string & text also as a system attribute. I assume it needs to pass as a parameter but can not figure that out nor could I find anything in the dictionary.

[AppleScript]
tell application “System Events”
tell process “Safari”
set Br to 75
set LastSt to “of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1”
repeat 30 times
try

			click button 1 of group Br of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
			--click button 1 of group Br & LastSt
			exit repeat
		end try
		set Br to Br + 1
	end repeat
end tell

end tell
[/AppleScript]

Thanks for looking

Peter

You can’t use a string for GUI scripting. You would use the actual GUI object in a variable instead

Like this

tell application "System Events"
	tell process "Safari"
		set Br to 75
		set LastSt to UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
		repeat 30 times
			try
				--click button 1 of group Br of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
				click button 1 of group Br of LastSt
				exit repeat
			end try
			set Br to Br + 1
		end repeat
	end tell
end tell

EDIT- fixed missing “UI” before element 1

Thank you that worked, interestingly the script I posted was part of a senior tell block and when I changed to your solution it did not work so I put it into a separate tell block and it did. Just in case anyone else reads this you had left out UI before “element 1”.

Thank you again.