Renat Nagaev
Renat Nagaev

Reputation: 826

How to get selected ui element in applescript?

I'm trying to create script for application which doesn't have dictionary. How to get selected list item?

I need something like this

tell application "System Events" tell process "process" get selected item of list 1 of splitter group 1 of window 1 end tell end tell

_

choose from list list 1... fails with 1700 error (can't convert to string)

Upvotes: 4

Views: 2900

Answers (1)

CRGreen
CRGreen

Reputation: 3444

Unfortunately the selected property of each of those particular elements (which are static text UI Elements) seems to be inaccessible. Doing the following:

activate application "SongOfGod_1_2"

--(this line above is just to make sure
-- we don't miss anything by not having the app frontmost;
--for many commands it is unnecessary)

tell application "System Events"
    tell process "SongOfGod"
        properties of static text 2 of list 1 of splitter group 1 of group 1 of splitter group 1 of window 1
    end tell
end tell

returns:

{class:static text, minimum value:missing value, orientation:missing value, position:{595, 259}, accessibility description:"2. And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.", role description:"text", focused:false, title:missing value, size:{1605, 18}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXStaticText", value:missing value, subrole:missing value, selected:missing value, name:missing value, description:"2. And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters."}

You'll notice, if you scroll way out there, that the selected property returns missing value, which means you cannot determine if it is selected. I also tried focused, which doesn't work. Nor do click or select work. Trying to get the selected property of the list containing it also doesn't work.

You apparently cannot get what you want out of this app, I'm sorry to say.

Upvotes: 2

Related Questions