AppleScript to Get text from an obscure object AXTextArea

I’m trying to use AppleScript in an automator workflow to get text from a window that I just opened via the same AppleScript.

Essentially here is what is happening with the script:

  1. Script is called using a keystroke with text selected
  2. Script gets open application and executes command+0 to open a file (in this case a patient chart in proprietary patient management software) then command+L to create a letter. New window with letter pops open correctly.
  3. This letter window contains an element that I cannot seem to get to with AppleScript. Ideally I would like to capture the value contained in this element (in this case the url https://some.website.somewhere/indext.html?var=value… ) and then subsequently open the URL in Safari.

This element is a text area (dashed line around the outside). When double clicking on it then inspecting it with Accessibility inspector it is AxTextArea and I’m trying to get the Value property which contains the string/URL

I’ve tried scroll area 1 of window 1 but from there I don’t know how to access this element.

Any ideas? Sorry, new user, it won’t let me post more than one image at a time so I took a combined screenshot.

Screenshot 2025-11-17 at 1.56.31 PM

Doesn’t “Accessibility Inspector” show the hierarchy of the element?

You can investigate by doing things like:
tell app “System Events”
tell app process “topsOrtho”
ui elements of window 1
end tell
end tell

( Sorry about the lack of formatting - posting from my phone. )

Then, depending on what result you get, add the sub-elements into that “ui elements of” line, until you find the object.

Sort of…The element that contains the text is of type text entry area with a parent scroll area. It’s confusing though because I find this by clicking on the desired object, but the scroll area does not seem to show it as a child. Its confusing.

Run the script below and post the results, so we can see how many scroll areas there are.
You might be referencing the wrong one.

tell application "System Events"
	tell application process "topsOrtho"
		get count (scroll areas of window 1)
	end tell
end tell
application "System Events"
	tell application process "Tops Ortho"
		UI element of window 1
	end tell
end tell

yields

{scroll area 1 of window "*End of Treatment Letter Helper" of application process "topsXtreme" of application "System Events", button 1 of window "*End of Treatment Letter Helper" of application process "topsXtreme" of application "System Events", button 2 of window "*End of Treatment Letter Helper" of application process "topsXtreme" of application "System Events", button 3 of window "*End of Treatment Letter Helper" of application process "topsXtreme" of application "System Events", static text "*End of Treatment Letter Helper" of window "*End of Treatment Letter Helper" of application process "topsXtreme" of application "System Events"}

and the following

tell application "System Events"
	tell application process "Tops Ortho"
		get count (scroll areas of window 1)
	end tell
end tell

yields

1

Now run this

application "System Events"
	tell application process "Tops Ortho"
		get count (UI elements of scroll area 1 of window 1)
	end tell
end tell

Shared Text UI elements is your children.

Type in more text and wa

Count is 3. There are two scroll bars and a pop up button. @technomorph how do I get to the child that is of type “text entry area”


Found it finally…

tell application "System Events"
	tell application process "Tops Ortho"
		value of UI element 1 of scroll area 1 of window 1
	end tell
end tell

gives me the text I want. The text entry area does not seem to be accessible using “text entry area”

1 Like

Try this…

application "System Events"
	tell application process "Tops Ortho"
		get text field 1 of scroll area 1 of window 1
	end tell
end tell

But…I’m discovering that it only works if the text entry area is in focus and in a mode where the text can be edited. Shoot I thought I had it. Any other clues?

When it’s not in focus, what UI elements are visible?

Only the two scroll bars and popup button. dashed line square that the text is in is nowhere to be found until it is clicked on and cursor enters the text area.

In Apple script, what UI element class is the square that you click on?

It is of type “text entry area”. Accessibility Inspector shows that the element class is “PlaceholderTextView”

This element is not present in either Accessibility Inspector or UI Browser until it is double clicked on to place the cursor inside as if to edit it. Hope that makes sense. See Screenshot.

How many text areas are in scroll area 1 of window 1?

None, unless the box has been clicked on to enter and the cursor is in there. Then it shows up.

I’ve tried to script a double click there but that is also not working for me. The scroll area 1 of window 1 I can get to. The resulting text entry area of class PlaceholderTextView I cannot seem to get my script to access.

I’m trying to determine the class of the area you need to click to get the text area to appear.

Yeah that usually happens with obscure UI elements that system events doesn’t recognize.

You got it right