Paste text to last active window

Good morning and thank you for your dedication!

So here is the full history log:

Thank you.

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

Omg! You are right!

There was probably a silent update!

Now the default text for the third button is empty instead of “Select” and underneath there are 3 radio buttons.

So here we are:

@epaminos,

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.

Hooray!!!

I recorded the following actions in Automator as advised and finally it works!

Events:
-Mouse Clicked
-Click the text area.
-Click the text area.
-Press ⌘V

I have no words!

Thank you all guys for your dedication!

Your commitment is unparalleled!

Thank you.

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

Added two forgotten instructions.

Yes, I followed your steps and had cliclick already installed as advised.

So once again the value of the static text is not set.
Alas your history doesn’t tell me if the property useClipboard was set to true or if it was set to false.
I carefully wrote instructions about that at the beginning of the script:


#===== ===== ===== ===== ===== ===== 
property useClipboard : true -- try with both settings <<<<<<<<<<<<<<<<<<<<<<<
-- true --> use the clipboard
-- false --> doesn't use the clipboard
#===== ===== ===== ===== ===== ===== 

and I don’t understand why there is no report about the clicclick action in your history.

I will post a log of what I get when I use it.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 17:21:09

OOPS, it’s my fault, I forgot two instructions.

Wait a minute I, will add them in the script above.

What is returned by the edited version in message #46 ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 9 mai 2020 21:53:53

So here are the new History Logs:

property useClipboard : true

property useClipboard : false

Thank you.

Now the contents of the static text is modified.
I don’t know why after keystroking “applescript” the field become “Applescript” but maybe there such formatting at work in the application.

It seems that there was again a silent update because in the history embedder in the message # we may read:

which prove that there was a 6th group containing the UI elements : → {button, group}

Today we may read :

which prove:
(a) that the static text was modified: by the keystroke action (but it wasn’t by the paste one)
I will edit the script accordingly.
display dialog “oldValue1 = Optional, newValue1 : Optional, altValue1 : AppleScript”
newValue1 confirm that set value did nothing
altValue1 confirm that the original value was replaced by “Applescript”
I’m curious to learn if you get an uppercase if you type “applescript” by hand.

(b) and prove that the group 6 which was available in message #47 is gone.
get class of every UI element of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of window 1 of process “Salary” whose subrole = “AXFloatingWindow”
→ error number -1719 from window 1 of process “Salary” whose subrole = “AXFloatingWindow”

Clearly your developer is unfair which doesn’t warn you when he introduce changes in the structure of the window.
Happily such change was trapped by a try / end try block but I must say that if I had to work with such a developer, he would ear how I can react to such flippancy.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 10 mai 2020 10:22:46