Sunday, May 9, 2021

#1 2021-04-09 05:25:08 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 261

Concatenate a GUI string

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

Applescript:


[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

Applescript:

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.

Offline

 

#2 2021-04-09 10:05:51 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1788

Re: Concatenate a GUI string

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:

Applescript:


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:

Applescript:


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"

Last edited by KniazidisR (2021-04-10 02:43:57 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2021-04-10 01:09:48 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 261

Re: Concatenate a GUI string

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.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)