Claude Cherton
Claude Cherton

Reputation: 11

How to get UI_element properties with appscript

I want to write code in appscript.rb equivalent to Applescript:

tell App "TextEdit"
    properties of front window
end tell

Trying

te =  app("TextEdit")
puts        te.windows[1].properties

returns the list of property names but no value.

Thanks to answer.

Upvotes: 0

Views: 193

Answers (1)

Chris Johnsen
Chris Johnsen

Reputation: 224581

The Ruby Appscript equivalent to AppleScript’s properties reference has a trailing underscore: properties_. You will also need to use get to execute the query:

te = Appscript.app('TextEdit')
te.windows.first.properties_.get

The result of the last expression will be an instance of Ruby’s Hash class.


The title of your question mentions UI_element, which might indicate that you are interested in the UI elements objects available from System Events.

se = Appscript.app('System Events')
teap = se.application_processes['TextEdit']

# properties of frontmost UI element window
teap.windows.first.properties_.get

# properties of first-level UI elements of frontmost UI element window 
teap.windows.first.UI_elements.properties_.get

Upvotes: 0

Related Questions