2

The documentation for JXA is lacking, so it would be extremely useful to be able to see the methods, variables, signatures, etc of the elements we deal with in the code. Unfortunately I haven't found a way to do this.

Given a JS variable, arising from a JXA script, how can I see all the methods that it contains? I am not familiar with JS, but the standard methods suggested here, console.dir() and JSON.stringify() did not work.

Practical example. To create and get the title of a Terminal window I can do

terminal = Application('Terminal')
terminal.quit()
terminal.activate()
delay(0.2)
title = terminal.windows()[0].name()
console.log(title)

My knowledge that I have to call windows(), and then, after subscripting, to call name(), came from a code on the web. I would like to be able to see the method windows() programmatically, like you get when you type __dir__() in Python. As said, the methods standard methods listed above did not help.

How can I proceed?

Nisba
  • 3,210
  • 2
  • 27
  • 46
  • You look it up in the application's scripting dictionary. – CJK Jul 12 '20 at 13:02
  • Thanks, I discovered it only after posting the question. Does every app come with that dictionary? – Nisba Jul 13 '20 at 11:52
  • 2
    In theory, yes, every _scriptable_ app will have a dictionary. If you drag an application into Script Editor's library window, it'll be added to the list iff it is scriptable and has a dictionary. It's literally the cornerstone of knowing how to interact with the app using AppleScript, and it can display the JXA forms if you prefer that (although the rule to mutate `ascr` terms into `jscr` equivalents is simple and consistent, but there is some functionality that AppleScript has but JXA has no means of doing (or wouldn't make sense in JavaScript). – CJK Jul 13 '20 at 16:31

1 Answers1

1

You can use the Apple provided Script Editor and browse the "documentation" of the app.

  1. Open Script Editor App
  2. Open: Window -> Library
  3. Double click the app in the library window or add it with the (+) icon

Now you can browse the app methods/functions

The "Terminology" search at the top is super helpful to find where a method might be hiding.

doc view search view

hashier
  • 4,670
  • 1
  • 28
  • 41