Have a routine that use GUI to get data from the web. Most of the string is repetitive and I have been trying to work out how to build the operative string by setting the repetetive part as a (string, text etc) without success.
As an example this works
[tell application "System Events"
tell process "Safari"
set OptDate2 to get value of pop up button 1 of group 2 of group 16 of group 1 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window
end tell
end tell
This does not
set StrEnd to " group 1 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"
tell application "System Events"
tell process "Safari"
set optdate to value of pop up button 1 of group 2 of group 16 of StrEnd
end tell
end tell
I guess its simple but I cannot figure it out.
Hi,
It isn’t concatenating the strings. You want build full reference from its parts. So, StrEnd should be a reference, not string. You assign part of reference to variable inside tell block this simple way:
tell application "System Events" to tell process "Safari"
set referenceEnd to group 1 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
set optdate to value of pop up button 1 of group 2 of group 16 of referenceEnd
end tell
Other, real working example: getting current date from certain MacScripter page, on my Safari:
tell application "Safari" to open location "https://macscripter.net/viewtopic.php?pid=206372#p206372" -- this page
tell application "System Events" to tell process "Safari"
set tabgroupUIElement to tab group 1 of splitter group 1 of window 1
set scrollareaUIElement to scroll area 1 of group 1 of group 1 of tabgroupUIElement
set groupUIElement to group 1 of UI element 1 of scrollareaUIElement
set optdate to value of static text 1 of groupUIElement
end tell
--> "Saturday, April 10, 2021"
Thank you I thought I had tried everything goes to show you learn every day. This will made a very long script far more readable.