Can't get Window

Need some input on GUI Scripting. Trying to reference a window, but keep getting an error. Any input would be helpful.

Error I’m trying to understand:

If I use the following code:

tell application "System Events" to tell application process "MyApplication"
	set stuff to entire contents of front window
end tell
return stuff

I get this result:

The specific UI element I’m trying to access is the

but the error comes up when trying to access anything within the nested windows called “Refresh All Extracts”.

Here is the way I do the job when I must use GUI scripting.
I start with the first level in the UI elements chain

tell application "System Events" to tell application process "Safari" --"MyApplication"
	set frontmost to true
	tell window 1
		class of every UI element
		-->{splitter group, button, button, button, group, button, toolbar}
	end tell
end tell

then I add code grabbing the second level

tell application "System Events" to tell application process "Safari" --"MyApplication"
	set frontmost to true
	tell window 1
		class of every UI element
		-->{splitter group, button, button, button, group, button, toolbar}
		tell first splitter group
			class of every UI element
			--> {splitter, tab}
		end tell
	end tell
end tell

Then I continue to add levels one by one so I quickly reach the wanted level :

tell application "System Events" to tell application process "Safari" --"MyApplication"
	set frontmost to true
	tell window 1
		class of every UI element
		-->{splitter group, button, button, button, group, button, toolbar}
		tell first splitter group
			class of every UI element
			--> {splitter, tab}
			tell last UI element
				class of every UI element
				--> {group}
				tell first UI element
					class of every UI element
					--> {group}
					tell first UI element
						class of every UI element
						--> {scroll area}
						tell first UI element
							class of every UI element
							--> {UI element, scroll bar}
							tell first UI element
								class of every UI element
								--> {UI element, scroll bar}
								tell group 2
									class of every UI element
									--> {static text}
									properties of first static text
									--> {minimum value:missing value, orientation:missing value, position:{2273, -181}, class:static text, role description:"texte", accessibility description:"", focused:false, title:"", size:{112, 11}, value:"Sunday, March 20, 2016", help:"", enabled:true, maximum value:missing value, role:"AXStaticText", entire contents:{}, subrole:missing value, selected:false, name:"Sunday, March 20, 2016", description:""}
								end tell
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) dimanche 20 mars 2016 10:00:22

Thanks for the in depth response. Unfortunately I still can’t seem to reference the window I’m trying to get to. Here’s the output:

tell application "System Events"
	tell process "Tableau"
		tell window 1
			class of every UI element
				-->{button, button, button, window, static text}
		end tell
	end tell
end tell

Taking it a step farther results in an error:

tell application "System Events"
	tell process "Tableau"
		tell window 1
			tell window 1
				class of every UI element
				-->[b]error[/b] [i]"System Events got an error: Can't get window 1 of window 1 of process \"Tableau\"." number -1728 from window 1 of window 1 of process "Tableau"[/i]
			end tell
		end tell
	end tell
end tell

What with :

tell application "System Events"
	tell process "Tableau"
		set frontmost to true
		tell window 1
			class of every UI element
			-->{button, button, button, window, static text}
			properties of UI elements
			-- properties of first static text # to get only those of the static text
		end tell
	end tell
end tell

I’m not sure that the window listed among the UI elements of the first window really exists.
Maybe it’s here exactly as some menu items are listed among those of a menu but aren’t displayed.

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) mercredi 23 mars 2016 08:31:05

tell application "System Events"
	tell process "Tableau"
		tell front window
			set stuff to entire contents of every UI element
		end tell
		return stuff
	end tell
end tell

returns:

tell application "System Events"
	tell process "Tableau"
		tell front window
			set stuff to entire contents of every UI element
		end tell
		item 8 of item 4 of stuff
	end tell
end tell

returns:

static text "Refreshing..." of group 1 of window "Refresh All Extracts" of window "Refresh All Extracts" of application process "Tableau" of application "System Events"
tell application "System Events"
	tell process "Tableau"
		tell front window
			set stuff to entire contents of every UI element
		end tell
		value of item 8 of item 4 of stuff
	end tell
end tell

Expected (hoped?) to get the “Refreshing…” text back. The goal is that I can watch for that to see when a refresh process is complete. No matter what I try it unfortunately returns the error:

May you test the script which I posted ?

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) mercredi 23 mars 2016 17:51:38

If you are unable to resolve your question/issue with @Yvan’s help, or you’d like more info, you can download the Apple Accessibility Inspector, called “UIElementInspector”, from here:
UIElementInspector – Apple Mac Developer Library

There is a “Download Sample Code” button at the top left, but fortunately the zip file includes the built app. So you don’t need Xcode.

For more info on using this tool, see:
A Strategy for UI Scripting in AppleScript

While I have downloaded and run this app, I haven’t used it much so far. So I can’t personally vouch for it.

I compared in details the two log which you posted. They aren’t describing the same UI elements.

According to your messages,
set stuff to entire contents of front window returned :
of application process “MyApplication” of application “System Events” # the process is not named Tableau but MyApplication
{
button 1 of window “Refresh All Extracts”,

button 2 of window “Refresh All Extracts”,

button 3 of window “Refresh All Extracts”,

window “Refresh All Extracts” of window “Refresh All Extracts”,
static text “The following extracts will be refreshed.” of window “Refresh All Extracts” of window “Refresh All Extracts”,
list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
static text 1 of list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
static text 2 of list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
static text “Refreshing…” of group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
progress indicator 1 of group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
button “Cancel” of group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,

static text “Refresh All Extracts” of window “Refresh All Extracts”
}

while
tell front window
set stuff to entire contents of every UI element

returned :
of application process “Tableau” of application “System Events” # this time the process is named Tableau
{
{}, # the button 1 (entire contents of a button is always an empty list)
{}, # the button 2
{}, # the button 3
{ # the entire contents of (sub)window 1
static text “The following extracts will be refreshed.” of window “Refresh All Extracts” of window “Refresh All Extracts”,
list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
static text 1 of list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
static text 2 of list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
static text 3 of list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”, # no such item in 1st log
static text 4 of list 1 of window “Refresh All Extracts” of window “Refresh All Extracts”, # no such item in 1st log
group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
static text “Refreshing…” of group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
progress indicator 1 of group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”,
button “Cancel” of group 1 of window “Refresh All Extracts” of window “Refresh All Extracts”},
{} # the static text (entire contents of a button is always an empty list)
}

Your thread is the very first one in which I see the instruction : entire contents of some UI element.
As your window contain few elements it’s not too difficult to rebuild the meaningful hierarchy as I did above.
When I applied it to the window of this thread, I got more than 1000 descriptors of UI elements which is not easy to decipher.

My understanding is that the (sub)window is displayed when one of the buttons of the main window is depressed but I’m not sure of that because I never encountered such behavior :
a (sub)window listed as UI element of a window but un seen when we try to extract its properties.

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) jeudi 24 mars 2016 11:19:35