Applescript API Documentation

I want to make AppleScript to automate the task of switching resolution on a MacBook Pro Retina.

Searching the Internet for โ€œapplescript system settingsโ€ I came across a page that shows some settings. Being a modified version of a new thing, it is not documented.

This leads to a bigger problem that I encountered with AppleScript (remember that in addition to copy-paste, I never programmed anything in it). Where, for example, is the documentation that tells me that the "System Preferences" object is actually called "System Preferences", that it has objects called the "panel", they have an identifier and that the exposure identifier is "com.apple.preference. expose "?

It seems that for each program there should be some "secret" documentation, and they should be huge, displaying all the hierarchies of objects and possible actions. After all, the core of AppleScript is minimal, and all you do is manipulate such programs. But where are they documented?

+4
source share
4 answers

Ok, here is how it works:

Where is the documentation that tells me, for example, that the "System Preferences" object is actually called "System Preferences"

The object is called System Preferences because it is the exact name of the application. What do you say with Applescript with this, I want to talk to an application called System Preferences ( tell application "System Preferences" ... )

that it has objects called a panel

Now this is the fun part. If you open the "Library" window (in the Applescript editor, "Window"), you will see that there is a set of applications available for scripting, the fact is that the "System Settings" is not there. So find it: File> Open Dictionary> System Preferences. Now you have a window that allows you to expand all available classes / commands / properties of the application, as well as a split window with the relevant documentation (if you click S System Preferences , you will see C pane and clicking on it, you will see P id among others) . The panel identifier will once again be the panel name (with bottom and concatenated - I'm still looking for documentation to strictly define this). Hope this helps you get started.


S : Suite C : Class P : Real Estate (โ€œCโ€ inside the circle means Command )
+5
source

You are absolutely right. Each program has its own documentation for applescript. He called it a dictionary of vocabulary. You can see the dictionary of any application with any of the following ...

1) in the AppleScript editor, on the File menu, select "Open Dictionary ...". You can select an application and it will display its dictionary.

2) Drag the application onto the AppleScript editor icon.

3) there is a list of frequently used dictionaries for quick access. From the Window menu in the AppleScript editor, select Library. You can double-click the application in this list. You can also modify this list to contain the dictionaries you want in the list.

Good luck.

+3
source

You can ask AppleScript to provide you with identifiers for each panel.

 tell application "System Preferences" to get the id of every pane 

This is especially convenient since it will give you identifiers for any third-party preference panels that you have set. For example, I was able to find out that the panel for my Microsoft Natural keyboard is called com.microsoft.microsoftkeyboard

I have not yet studied this problem, but I would expect that a similar syntax exists to identify objects in any scripted application.

0
source

I have one more problem, but you can take a look at my question as there is some hint about your problem in my script.

HOW: show a checkmark, disable the menu item, update the menu ...

For instance:

 tell application "System Preferences" reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays" end tell 

This code should explicitly indicate in the resolution settings of the system preference.

Then you can create code to restore all the panel user interface elements so that you now activate the action. Something like this should also work:

 tell application "System Events" tell application process "System Preferences" set frontmost to true delay 1 return every UI element of front window return name of every UI element of front window end tell 

end tell

Hope this helps

0
source

All Articles