Getting text from sheet of window?

At my office we use a program called BRU PE to archive files to LTO tapes. It’s a good program except it doesn’t provide any notifications when you need to swap tapes, aside from a popup. Since we run it on a headless Mac, this is an issue.

I decided that I would try and write an Applescript to detect when that popup appears, and send notifications. After a bit of poking around I figured out that the popup was a sheet, and I was able to detect when it appears by running the following in a loop:

tell application "System Events"
			tell process "BRU PE"
				if exists sheet of window 1 then
					# Send a notification
				end if
			end tell
		end tell

While this code works, I want to make it a bit smarter by allowing it to read and parse the text on the sheet. The sheet will say something like “Insert tape x of y,” but I can’t figure out how to actually read text off of a sheet. I’ve tried a couple different things, but none of them work. One example of non-working code:


tell application "System Events"
			tell process "BRU PE"
				if exists static text of sheet of window 1 then
					# Do something with it
				end if
			end tell
		end tell

If anyone has any ideas for trying to read text off of a sheet, I’d love to hear it. I’m able to read the text of buttons on the sheet but that’s not really good enough for what I want to do.


set textIndex to 1 # maybe there are more
tell application "System Events"
	tell process "BRU PE"
		if exists static text textIndex of sheet 1 of window 1 then
			set itsText to its value # Do something with it
		end if
	end tell
end tell

#=====

set textIndex to 1 # maybe there are more
tell application "System Events"
	tell process "BRU PE"
		if exists static text textIndex of sheet 1 of window 1 then
			my notify("The popup is available.", "Caution !")
		end if
	end tell
end tell

#=====

on notify(theNotification, theTitle)
	if (system attribute "sys2") < 10 then
		# Thanks to Shane Stanley, display a notification in Mavericks 2015/02/10
		# Requires the file : /Library/Script Libraries/Show-Remove-Notification lib.scptd
		
		tell script "Show-Remove-Notification lib" to its notifyWithTitle:theTitle andSubtitle:theNotification
	else
		display notification theNotification with title theTitle # uniquement pour Yosemite
	end if
end notify


Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) mercredi 8 juin 2016 16:43:29

Hey Yvan, thanks for the reply. Unfortunately I tried that method already (adding the index after static text) and it isn’t able to get the text this way.

I tried using the Accessibility Inspector to gain some insight into the UI elements but I didn’t find anything conclusive:

I apologize but the selected item is not a text item but is an AXUnknown one.

So, it’s really not surprising that the code written according to what you described fails.

More, Accessibility Inspector doesn’t report the content of the selected object .
You may try to download UI Browser from : http://pfiddlesoft.com
but honestly I doubt that somebody will be able to do the job.

Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) mercredi 8 juin 2016 17:41:10