I want to do something like the following:
container of (1st static text of rows of tables of ¬
scroll areas of (1st window whose title contains ¬
"motorola") whose value contains "16225")
--> row N of table N of scroll area N of …
Thoughts?
Use value of attribute "AXParent". attributes of shows other attributes of UI elements.
tell application "System Events" to tell process "Finder"
value of attribute "AXParent" of some UI element of window 1
end
Related
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)
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.
I'm trying to get the window whose document has the name "book.pdf". Here's my approach
tell application "Preview"
set w to every window whose document is named "book.pdf"
end
This doesn't work. I've tried about 100 permutations but I'm not getting anywhere. Any tips?
You can use AXTitle combined with contains, and tell System Events not Preview
Note I have it wrapped in a try block because myWindow will be undefined if no string match is found.
set n to "book.pdf" -- whatever substring you want to find
tell application "System Events" to tell process "Preview"
try
set myWindow to (1st window whose value of attribute "AXMain" is true and value of attribute "AXTitle" contains n)
log myWindow
on error
log "not found"
end try
end tell
I need to get the coordinates {X,Y} of an element in order to generate a click event on it (I can't do that by using "click" since System Events has problem doing that and returns: "missing value"). I'll use these coordinates to pass them to a command line tool that simulates a mouse click.
How can I achieve that?
Can you get the properties of the ui element? I think you can even if you can't actually click it. One of the properties should be "position" and another will be "size". Those 2 things should help you find the screen coordinates so you can click the element.
For example try this and look at the properties...
tell application "System Events"
tell process "Safari"
properties of UI element 1 of window 1
end tell
end tell
So if I wanted to know the coordinates of the middle of that element so you can click it this would give you the x and y coordinates of where to click...
tell application "System Events"
tell process "Safari"
tell UI element 1 of window 1
set p to position
set s to size
end tell
end tell
end tell
set xCoordinate to (item 1 of p) + (item 1 of s) / 2
set yCoordinate to (item 2 of p) + (item 2 of s) / 2
return {p, s, xCoordinate, yCoordinate}
10.7.4 OSX Lion
Applescript
I am working with an application (built in house and has no Applescript dictionary) that has a static text element I want to copy to the clipboard and send to another app but I'm having a hard time getting it to work.
The script I was using for targeting the element looked like this:
Tell application "System Events" to set frontmost of process "*application*" to true
Tell application "System Events"
Tell process "*application*"
Tell static text 1 of tab view 1 scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1
keystroke "a" using command down
delay 0.1
keystroke "c" using command down
delay 0.1
end tell
end tell
end tell
end tell
What would happen was that the wrong text from the wrong element was copied to the clipboard every time I clicked in a different spot on the application (there are numerous text fields).
I noticed in UI Accessor/Accessibility Accessor that each UI element in the application has a unique AXIdentifier value when you mouse over them.
Is there anyway to accomplishing what I am trying to do, using AXIdentifier values to target that element and copy the text from it?
Thanks for all the help this is my first post and I hope it was worthy! ~TheLarkInn
You can do this by using AppleScript's filtering. For example, to get the From: pop-up menu in a message composition window in Apple Mail, there is no accessibility description you can match on, however there is a unique AXIdentifier which you can match as follows:
tell application "System Events"
tell application process "Mail"
tell window 1
get first pop up button whose value of attribute "AXIdentifier" is "popup_from"
end tell
end tell
end tell
This is more efficient than looping in AppleScript as it only involves sending one Apple Event to System Events.
I don't think there is a way to directly do what you're trying to do. It seems like you can only access attributes once you have a handle on an element via selector. Here is a very ugly solution that does what you're asking by iterating over all UI elements, but it is really slow with bigger UIs and probably not ideal for any production level code.
tell application "System Events"
tell process "Some Process"
set tElements to entire contents of window "Some Window"
repeat with tElement in tElements
if (exists attribute "AXIdentifier" of tElement) then
if value of attribute "AXIdentifier" of tElement = "Some AXIdentifier" then set tText to value of tElement
end if
end repeat
end tell
end tell
tText
I think using UIElementInspector or Accessibility Inspector from Xcode to build a selector string is the way to go!
Tell application "*application*" to activate
Tell application "System Events"
Tell application process "*application*"
set textStaticTextValue to value of static text 1 of tab view 1 scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of window 1
end tell
end tell
AppleScript’s list data type has only a very limited support for boolean test specifiers. Besides picking items by range (with the item keyword), specifying a class will work:
get every «class furl» of {1, "Test", (POSIX file "/posix/path")} --> {file ":hfs:path"}
When the list items are references, dereferencing with the contents keyword will work:
get every «class furl» of {1, "Test", a reference to (POSIX file "/posix/path")} --> {}
get every «class furl» of contents of {1, "Test", a reference to (POSIX file "/posix/path")} --> {file ":hfs:path"}
So why does the following code set allTextAreas to an empty list:
tell application "System Events"
set allUIElements to entire contents of window 1 of someApplication
set allTextAreas to every text area of contents of allUIElements --> {}
end tell
given that allUIElements is a list of references to UI element objects, and that at least one of them is of class text area?
Note I am not looking for suggestions how to retrieve all UI elements of a certain type from the list (a repeat loop will do that) – I would like to understand why the selector pattern fails in this specific case.
Here's how I would do it if I wanted to find all the buttons of the front window in Safari. Just apply this logic to your situation.
tell application "System Events"
tell process "Safari"
set allButtons to UI elements of window 1 whose class is button
end tell
end tell
Getting the UI elements from the application results in a list of object specifiers: application objects (a form of nested containers) where each item in the hierarchy has several properties, including a class – Technical Note TN2106 might shed more light on this –, while your first example used a file URL (a type of file reference) which has a base class.
So you will need to use either an application filter reference form when getting the objects from the application or query the desired properties of the returned objects, for example:
set allButtons to {}
tell application "System Events" to tell application process "Safari"
set allUIElements to entire contents of window 1
repeat with anElement in allUIElements
try
if class of anElement is button then set end of allButtons to contents of anElement
end try
end repeat
end tell
allButtons