So, if as you wrote, the window “Report” is a floating window,
group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 of window “Report” of application process “Salary” of application “System Events” really exists.
I carefully wrote:
It seems that you missed the important words : For instance
I wrote 3 as I would have written 987 because as I am not a sooth sayer I can’t guess which is the real index of the static text to set. Now, given your screenshot, I assume that the true index is 1, so, may you try to use this subset of the script
set theExtension to "applescript"
tell application "System Events" to tell process "Salary"
set frontmost to true
tell (first window whose subrole is "AXFloatingWindow")
set itsName to its name
log its properties -- ADDED to get infos upon the window
if exists group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 then
set value of static text 1 of group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 to theExtension
else
error "there is no group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 in the window “" & itsName & "”"
end if
end tell
end tell
and let me know if it correctly replace the word “Optional” by the word “applescript”.
If it doesn’t, let me know what is reported in the log history.
You may also try this alternate version in which I assume that you have a single window named “Report”
set theExtension to "applescript"
tell application "System Events" to tell process "Salary"
set frontmost to true
tell window "Report"
log its properties -- ADDED to get infos upon the window
if exists group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 then
set value of static text 1 of group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 to theExtension
else
error "there is no group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 in this window “Report”"
end if
end tell
end tell
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 7 mai 2020 18:14:32
set theExtension to "applescript"
tell application "System Events" to tell process "Salary"
set frontmost to true
tell window "Report"
log its properties -- ADDED to get infos upon the window
if exists group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 then
tell text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1
class of UI elements --> it's supposed to return at least {group, group}
tell group 1
class of UI elements --> I have no idea of what it's supposed to return {???}
end tell -- group 1
tell group 2
class of UI elements --> it's supposed to return at least {static text}
properties of every static text
set value of static text 1 to theExtension
delay 0.2
properties of static text 1
end tell -- group 2
end tell -- text area 1…
else
error "there is no group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 in this window “Report”"
end if
end tell -- window "Report"
end tell -- "System Events"…
and return the entire log history.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 7 mai 2020 19:45:40
The static text doesn’t obey to the instruction “set value”
Must try to use paste or keystroke.
Download Cliclick from www.bluem.net
and install it as : “/usr/local/bin/cliclick”
By default, the folder “Macintosh HD:usr:” is invisible.
but you may open it with :
set p2usr to POSIX file "/usr/"
tell application "Finder" to open p2usr
If I remember well, a subfolder named “local” exists
but you will have to create its subfolder “bin” to get the hierarchy:
“Macintosh HR:usr:local:bin:” where you will store “cliclick”.
-- version 1
property useClipboard : true -- try both settings
-- true --> use the clipboard
-- false --> doesn't use the clipboard
set theExtension to "applescript"
if useClipboard then set the clipboard to theExtension
tell application "System Events" to tell process "Salary"
set frontmost to true
tell window "Report"
tell group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1
-- class of UI elements --> {static text}
set {x, y} to position of static text 1
-- you may try to use : click at {x,y} -- but I doubt that it would work
tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y -- third party CLI to click upon the static text
if useClipboard then
keystroke "v" using {command down}
keystroke return
else
keystroke theExtension & return
end if
delay 0.2
class of UI elements --> {static element} + maybe a 2nd element
properties of text items
end tell
end tell
end tell
-- version 2
property useClipboard : true -- try both settings
-- true --> use the clipboard
-- false --> doesn't use the clipboard
set theExtension to "applescript"
if useClipboard then set the clipboard to theExtension
set theExtension to "applescript"
tell application "System Events" to tell process "Salary"
set frontmost to true
tell window "Report"
tell group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1
-- class of UI elements --> {static text}
set {x, y} to position of static text 1
end tell
tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y -- third party CLI to click upon the static text
if useClipboard then
keystroke "v" using {command down}
keystroke return
else
keystroke theExtension & return
end if
delay 0.2
class of UI elements --> {static element} + maybe a 2nd element
properties of text items
end tell
end tell
I will be back tomorrow.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 7 mai 2020 22:07:37
Hi again. I was at work. So, you found static text in the entire contents of floating window. But as remember, one static text is like label, so its value doesn’t change. Should be some text field or button, which corresponds to this static text.
2) you sad me that when you close other application’s window, you see at the top of the screen the name of floating window. That is, this window is already focused (selected). You should try to select not the floating window, but text field or button corresponding to your static text. And, the click, showed by Yvan Koenig in his last script, maybe double-click depending on your application’s realization.
NOTE: if selecting text field (or, button) works (select text field…blabla, or select button…blabla) or setting text field’s or button’s property focused to true, works, then you can click it without cliClick.
Of course, I guess that the name written at the very end : “Report k” is just a typo but it’s puzzling to read that the object which existed (with an embedded text field) in first case doesn’t exist in second case.
What changed between these two attempts ?
Is it a way to get a copy of the application ?
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 8 mai 2020 10:31:46
Are you sure that the window has the same contents during every tests ?
My understanding is that in some conditions which I can’t guess - but you are supposed to know them - the window contains the wanted UI element and that in other conditions it doesn’t.
Your message #30 was clear enough:
The “group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 of window 1 of process “Salary”” was available and it contained a static text whose value was “Optional”
In other attempts such object wasn’t available. I wonder how you were able to ran the script without seeing such difference.
I apologize, it’s your duty to take care of what is available in your window before trying to execute a given task.
So, please look carefully at what is available in your window before trying to run the script.
If the wanted text area it’s useless to try to edit its contents.
Here is a slightly modified release of the script version 1.
If the window doesn’t match the wanted item, it will not issue an error message to warn you, it will use a display dialog"
-- version 1
property useClipboard : true -- try both settings
-- true --> use the clipboard
-- false --> doesn't use the clipboard
set theExtension to "applescript"
if useClipboard then set the clipboard to theExtension
tell application "System Events" to tell process "Salary"
set frontmost to true
tell window "Report"
if exists group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 then
tell group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1
class of UI elements --> {static text}
value of static text 1
set {x, y} to position of static text 1
-- you may try to use : click static text 1 -- but I doubt that it would work
tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y -- third party CLI to click upon the static text
if useClipboard then
keystroke "v" using {command down}
keystroke return
else
keystroke theExtension & return
end if
delay 0.2
class of UI elements --> {static element} + maybe a 2nd element
properties of text items
end tell
else
display dialog "No need to continue, the window “Report” doesn't contain the wanted text area" buttons {"Oops"}
end if
end tell
end tell
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 8 mai 2020 17:22:41
Here is an expanded version which is supposed to return in the log history complementary informations which, I hope, will tell me what you failed to see.
set theExtension to "applescript"
tell application "System Events" to tell process "Salary"
set frontmost to true
name of every window
subrole of every window
tell (first window whose subrole is "AXFloatingWindow")
get its properties
end tell
tell window "Report"
set itsName to its name
get its properties -- ADDED to get infos upon the window
class of UI elements --> {group, ???, ???}
tell group 1
class of UI elements --> {group, ???, ???}
tell group 1
class of UI elements --> {scroll area, ???, ???}
tell scroll area 1
class of UI elements --> {UI element, ???, ???}
tell UI element 1
class of UI elements --> {group, group, group, group, group, ???, ???}
try
log "group 1"
tell group 1
class of UI elements --> {group, ???, ???}
tell group 1
class of UI elements --> {text area, ???, ???}
tell text area 1
class of UI elements --> {group, group, ???, ???}
tell group 1
class of UI elements --> {???, ???}
end tell -- group 1
tell group 2
class of UI elements --> {static text, ???, ???}
tell static text 1
its properties -->
end tell -- static text 1
end tell -- group 2
end tell -- text area 1
end tell -- group 1
end tell -- group 1
end try
try
log "group 2"
tell group 2
class of UI elements --> {group, ???, ???}
tell group 1
class of UI elements --> {text area, ???, ???}
tell text area 1
class of UI elements --> {group, group, ???, ???}
tell group 1
class of UI elements --> {???, ???}
end tell -- group 1
tell group 2
class of UI elements --> {static text, ???, ???}
tell static text 1
its properties -->
end tell -- static text 1
end tell -- group 2
end tell -- text area 1
end tell -- group 1
end tell -- group 2
end try
try
log "group 3"
tell group 3
class of UI elements --> {group, ???, ???}
tell group 1
class of UI elements --> {text area, ???, ???}
tell text area 1
class of UI elements --> {group, group, ???, ???}
tell group 1
class of UI elements --> {???, ???}
end tell -- group 1
tell group 2
class of UI elements --> {static text, ???, ???}
tell static text 1
its properties -->
end tell -- static text 1
end tell -- group 2
end tell -- text area 1
end tell -- group 1
end tell -- group 3
end try
try
log "group 4"
tell group 4
class of UI elements --> {group, ???, ???}
tell group 1
class of UI elements --> {text area, ???, ???}
tell text area 1
class of UI elements --> {group, group, ???, ???}
tell group 1
class of UI elements --> {???, ???}
end tell -- group 1
tell group 2
class of UI elements --> {static text, ???, ???}
tell static text 1
its properties -->
end tell -- static text 1
end tell -- group 2
end tell -- text area 1
end tell -- group 1
end tell -- group 4
end try
try
log "group 5"
tell group 5
class of UI elements --> {group, ???, ???}
tell group 1
class of UI elements --> {text area, ???, ???}
tell text area 1
class of UI elements --> {group, group, ???, ???}
tell group 1
class of UI elements --> {???, ???}
end tell -- group 1
tell group 2
class of UI elements --> {static text, ???, ???}
tell static text 1
its properties -->
end tell -- static text 1
end tell -- group 2
end tell -- text area 1
end tell -- group 1
end tell -- group 5
end try
end tell -- UI element 1
end tell -- scroll area 1
end tell -- group 1
end tell -- group 1
if exists group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 then
tell group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1
class of UI elements
set oldValue to value of static text 1
end tell --
else
display dialog "There is no group 2 of text area 1 of group 1 of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 in the window “" & itsName & "”" buttons {"Oops"}
end if
end tell -- window 1
end tell -- System Events"
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 8 mai 2020 17:54:00
The window active in your late test is definitely not the same than the one reported in your message #32 in which we read:
How may you miss the fact that you aren’t applying the script upon the same window ?
Maybe the developer changed the structure of its window but I hope that he is polite enough to inform you of such meaningful changes.
If he didn’t, urge him to inform you of what he does with the structure of the window.
What is sure is that, as I already wrote, the current window is not structured as it was before.
Given the posted log history, I edited my script which, now, try to grab infos about items which were unknown before and I try to edit the content of the new structure.
#===== ===== ===== ===== ===== =====
-- Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 14:27:54
#===== ===== ===== ===== ===== =====
#===== ===== ===== ===== ===== =====
property useClipboard : true -- try with both settings <<<<<<<<<<<<<<<<<<<<<<<
-- true --> use the clipboard
-- false --> doesn't use the clipboard
#===== ===== ===== ===== ===== =====
set theExtension to "applescript"
if useClipboard then set the clipboard to theExtension
tell application "System Events" to tell process "Salary"
set frontmost to true
-- name of every window --> {"Report", "Salary"}
-- subrole of every window --> {"AXFloatingWindow", "AXStandardWindow"}
-- Now we know that the floating window is named "Report"
tell (first window whose subrole is "AXFloatingWindow")
-- for safe, check that the floating window is really named "Report"
set itsName to its name --> "Report"
-- its properties --> {minimum value:missing value, orientation:missing value, position:{3150, 624}, class:window, accessibility description:missing value, role description:"floating window", focused:false, title:"Report", size:{560, 636}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXWindow", value:missing value, subrole:"AXFloatingWindow", selected:missing value, name:"Report", description:"floating window"}
class of UI elements --> {group, button, button, button, static text}
properties of buttons -->
properties of static text 1 -->
tell group 1
class of UI elements --> {group}
tell group 1 -- there is only one
class of UI elements --> {scroll area}
tell scroll area 1 -- there is only one
class of UI elements --> {UI element}
tell UI element 1 -- there is only one
class of UI elements --> {UI element, static text, group, static text, group, static text, group, static text, group, static text, group, group}
tell UI element 1
class of UI elements -->
end tell
properties of every static text -->
try
log ">>> group 1"
tell group 1
class of UI elements --> {pop up button}
tell pop up button 1
click it
tell menu 1
name of menu items -->
end tell
end tell -- pop up button 1
end tell -- group 1
end try
try
log ">>> group 2"
tell group 2
class of UI elements --> {pop up button}
tell pop up button 1
click it
tell menu 1
name of menu items -->
end tell
end tell -- pop up button 1
end tell -- group 2
end try
try
log ">>> group 3"
tell group 3
class of UI elements --> {pop up button}
tell pop up button 1
click it
tell menu 1
name of menu items -->
end tell
end tell -- pop up button 1
end tell -- group 3
end try
try
log ">>> group 4"
tell group 4
class of UI elements --> {radio button, radio button, radio button}
properties of radio buttons -->
end tell -- group 4
end try
try
log ">>> group 5"
tell group 5
class of UI elements --> {group}
tell group 1 -- there is only one
class of UI elements --> {text area, group}
tell group 1
class of UI elements -->
end tell
tell text area 1
class of UI elements --> {group} as reported in messages #34 and #38, was {group, group} as reported in messages #32
if (count every group) = 1 then
-- It was reported in messages #34 and #38
tell group 1
class of UI elements --> {static text}
set oldValue1 to value of static text 1 --> "Optional" ???
-- try to change the value the classic way
set value of static text 1 to "John Doe"
delay 0.2
set newValue1 to value of static text 1 --> "John Doe" if it's that, it's that the classic way works well
-- you may try to use : click static text 1 -- but I doubt that it would work
tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y -- third party CLI to click upon the static text
if useClipboard then
keystroke "v" using {command down}
keystroke return
else
keystroke theExtension & return
end if
set altValue1 to value of static text 1 --> "applescript" if it's that, it's that the alternate way works well
display dialog "oldValue1 = " & oldValue1 & ", newValue1 : " & newValue1 & ", altValue1 : " & altValue1
end tell -- group 1
else
-- It was reported in message #32
-- I keep it in case of possible return of this structure
tell group 2
class of UI elements --> {static text}
set oldValue2 to value of static text 1 --> "Optional" ???
-- try to change the value the classic way
set value of static text 1 to "John Doe"
delay 0.2
set newValue2 to value of static text 1 --> "John Doe" if it's that, it's that the classic way works well
-- you may try to use : click static text 1 -- but I doubt that it would work
tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y -- third party CLI to click upon the static text
if useClipboard then
keystroke "v" using {command down}
keystroke return
else
keystroke theExtension & return
end if
set altValue2 to value of static text 1 --> "applescript" if it's that, it's that the alternate way works well
end tell -- group 2
display dialog "oldValue2 = " & oldValue2 & ", newValue2 : " & newValue2 & ", altValue2 : " & altValue2
end if
end tell -- text area 1
end tell -- group 1
end tell -- group 5
end try
end tell -- UI element 1
end tell -- scroll area 1
end tell -- group 1
end tell -- group 1
end tell -- window 1
end tell -- System Events"
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 14:05:13
finding a reference for your text field can take a long time. See the method for finding a reference to a specific UI element using the user actions Record function of Automator.app. I showed this method to @daBee in the topic “Scripting qBittorent”. Everything is in the drawings there.
Here is an enhanced version supposed to grab more infos.
I’m a bit bored to see that you disabled the instructions which were inserted to try to change the text value.
How are you hoping that I will learn the way they behave if you disable them.
In message #33 I gave you the related instructions:
I do my best but I am unable to install Cliclick for you.
#===== ===== ===== ===== ===== =====
-- Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 18:12:54
#===== ===== ===== ===== ===== =====
#===== ===== ===== ===== ===== =====
property useClipboard : false -- Use this one because pasting didn't change the text
-- true --> use the clipboard
-- false --> doesn't use the clipboard, use keystroke theExtension & return
#===== ===== ===== ===== ===== =====
set theExtension to "applescript"
if useClipboard then set the clipboard to theExtension
tell application "System Events" to tell process "Salary"
set frontmost to true
-- name of every window --> {"Report", "Salary"}
-- subrole of every window --> {"AXFloatingWindow", "AXStandardWindow"}
-- Now we know that the floating window is named "Report"
tell (first window whose subrole is "AXFloatingWindow")
-- for safe, check that the floating window is really named "Report"
set itsName to its name --> "Report"
-- its properties --> {minimum value:missing value, orientation:missing value, position:{3150, 624}, class:window, accessibility description:missing value, role description:"floating window", focused:false, title:"Report", size:{560, 636}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXWindow", value:missing value, subrole:"AXFloatingWindow", selected:missing value, name:"Report", description:"floating window"}
class of UI elements --> {group, button, button, button, static text}
subrole of buttons --> {"AXCloseButton", "AXZoomButton", "AXMinimizeButton"}
value of static text 1 --> "Report"
tell group 1
class of UI elements --> {group}
tell group 1 -- there is only one
class of UI elements --> {scroll area}
tell scroll area 1 -- there is only one
class of UI elements --> {UI element}
tell UI element 1 -- there is only one
class of UI elements --> {UI element, static text, group, static text, group, static text, group, static text, group, static text, group, group}
tell UI element 1
class of UI elements --> {static text}
properties of static text 1
end tell
value of every static text --> {"Advisor", "Category", "Reason", "Rating", "Notes"}
try
log ">>> group 1"
tell group 1
class of UI elements --> {pop up button}
tell pop up button 1
its properties
click it
try -- it seems that there is no such classic level
tell menu 1
class of UI elements
end tell
end try
try
name of menu items -->
end try
end tell -- pop up button 1
end tell -- group 1
end try
try
log ">>> group 2"
tell group 2
class of UI elements --> {pop up button}
tell pop up button 1
its properties
click it
try -- it seems that there is no such classic level
tell menu 1
class of UI elements
end tell
end try
try
name of menu items -->
end try
end tell -- pop up button 1
end tell -- group 2
end try
try
log ">>> group 3"
tell group 3
class of UI elements --> {pop up button}
tell pop up button 1
its properties
click it
try -- it seems that there is no such classic level
tell menu 1
class of UI elements
end tell
end try
try
name of menu items -->
end try
end tell -- pop up button 1
end tell -- group 3
end try
try
log ">>> group 4"
tell group 4
class of UI elements --> {radio button, radio button, radio button}
description of radio buttons --> {"Rating 1 out of 3", "Rating 2 out of 3", "Rating 3 out of 3"}
end tell -- group 4
end try
try
log ">>> group 5"
tell group 5
class of UI elements --> {group}
tell group 1 -- there is only one
class of UI elements --> {text area, group}
tell group 1
class of UI elements -->
end tell
tell text area 1
class of UI elements --> {group} as reported in messages #34 and #38, was {group, group} as reported in messages #32
if (count every group) = 1 then
-- It was reported in messages #34 and #38
tell group 1
class of UI elements --> {static text}
set oldValue1 to value of static text 1 --> "Optional" ???
-- try to change the value the classic way
set value of static text 1 to "John Doe"
set {x, y} to position of static text 1 -- I forgot it so an error was silently issued below !
delay 0.2
set newValue1 to value of static text 1 --> "Optional"
-- The classic way to set the value doesn't work
-- I'm not surprised, it didn't with the old structure!
#===== ===== ===== ===== ===== =====
-- This group of instructions was not executed !!!!!!!!!
-- How may I know which scheme is working correctly ?
-- I can't install Cliclick for you !!!!!!
-- you may try to use : click static text 1 -- but I doubt that it would work
-- as {x, y} was not defined an error was silently issued. What an ass !
tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y -- third party CLI to click upon the static text
if useClipboard then
keystroke "v" using {command down}
keystroke return
else
keystroke theExtension & return
end if
set altValue1 to value of static text 1 --> "applescript" if it's that, it's that the alternate way works well
display dialog "oldValue1 = " & oldValue1 & ", newValue1 : " & newValue1 & ", altValue1 : " & altValue1
#===== ===== ===== ===== ===== =====
end tell -- group 1
else
-- It was reported in message #32
-- I keep it in case of possible return of this structure
tell group 2
class of UI elements --> {static text}
set oldValue2 to value of static text 1 --> "Optional" ???
-- try to change the value the classic way
set value of static text 1 to "John Doe"
set {x, y} to position of static text 1 -- I forgot it !
delay 0.2
set newValue2 to value of static text 1 --> "John Doe" if it's that, it's that the classic way works well
-- you may try to use : click static text 1 -- but I doubt that it would work
tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y -- third party CLI to click upon the static text
if useClipboard then
keystroke "v" using {command down}
keystroke return
else
keystroke theExtension & return
end if
set altValue2 to value of static text 1 --> "applescript" if it's that, it's that the alternate way works well
end tell -- group 2
display dialog "oldValue2 = " & oldValue2 & ", newValue2 : " & newValue2 & ", altValue2 : " & altValue2
end if
end tell -- text area 1
end tell -- group 1
end tell -- group 5
end try
try
tell group 6
class of UI elements --> {button, group}
properties of button 1
tell group 1
class of UI elements
end tell
end tell -- group 6
end try
end tell -- UI element 1
end tell -- scroll area 1
end tell -- group 1
end tell -- group 1
end tell -- window 1
end tell -- System Events"
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 16:25:49