Assuming that the static text you ask about in your second message really exists, every informations required to get its AXSelectedText value was available. Written in a single instruction it would be.
tell application "System Events" to tell process "Preview"
set frontmost to true
# Here I assume that the static text is available
tell static text 1 of scroll area 1 of splitter group 1 of window 1
set sel_txt to value of attribute "AXSelectedText"
end tell
end tell
But for user which aren’t at ease with GUI scripting, it’s safer to split the instruction as I did in my late message because the split code give the ability to navigate carefully in the structure of the GUI.
In my late message, as the code was split in single instructions, I was able to log their results.
Just to be precise, in your second message you aren’t asking about the same static text that the one asked about in your the one opening this thread !
The static text asked about in message #1 is really available.
The one which you ask about now doesn’t exist.
As I am curious and pig headed, even when the asker prove to be unable to describe correctly its problem I dig in the GUI trying to find the target object, and sometimes I get it.
It’s the case today but the static text is not in the described scroll area and it is deeper in the GUI hierachy.
tell application "System Events" to tell process "Preview"
set frontmost to true
tell window 1 # with a PDF file open and some words selected
class of every UI element
log result (*splitter group, button, button, button, toolbar, image, menu button, static text*)
class of UI elements of first splitter group
log result (*scroll area, splitter, scroll area*)
class of every UI element of first scroll area of first splitter group
# Here there is no static text
log result (*UI element, scroll bar*)
# Try deeper
class of every UI element of first UI element of first scroll area of first splitter group
log result (*image, image, image, image*)
# Nada !
# Try in the other scroll area
class of every UI element of scroll area 2 of first splitter group
# Here there is no static text
log result (*group, scroll bar*)
# try deeper in the hierarchy
class of every UI element of first group of scroll area 2 of first splitter group
log result (*static text*)
# BINGO, it's here !
tell first static text of first group of scroll area 2 of first splitter group
its value
log result (*How to Make a Bootable
OS X El Capitan Beta USB
Installer Drive
Jun 11, 2015 - 43 Comments
Many Mac users interested in running OS X El Capitan may wish to have a bootable install drive of the new operating system. We're going to demonstrate how to do this with a USB flash drive, but*)
name of its attributes
log result (*AXSelectedTextRange, AXEnabled, AXDescription, AXParent, AXSize, AXFocused, AXRole, AXTopLevelUIElement, AXPosition, AXTitle, AXValue, AXWindow, AXRoleDescription, AXVisibleCharacterRange, AXSelectedText, AXFrame*)
set sel_txt to value of its attribute "AXSelectedText"
log sel_txt (*OS X El Capitan Beta USB*)
end tell
end tell
end tell
Of course, if nothing is selected in the text, the value sel_txt will be set to missing value !
Next time, try to define precisely and exactly your problem. It would spare your time and mine.
When the hunt prove to be successful, and only in such case, it’s quite reasonable to try to write a compact code. Here it would be :
tell application "System Events" to tell process "Preview"
set frontmost to true
tell first static text of first group of scroll area 2 of first splitter group of window 1
set sel_txt to value of its attribute "AXSelectedText"
log sel_txt (*OS X El Capitan Beta USB*)
end tell
end tell
But without the step by step first one we would always be scrapping our head.
Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) samedi 19 décembre 2015 23:31:23