Basic AppleScript Terminology

AppleScript is not a difficult language to learn. Its plain English approach of "talking" to applications and elements is easily understandable. However, like any language, there are some variations in the words you can use; dialects, if you will. AppleScript is implemented by the developer of an application, so the commands and parameters may be conceptually the same as another application's, but using a different term. This is certainly not meant to be a complete guide to AppleScripting DEVONthink, but what follows are some common terms or concepts you're likely to encounter. The examples here and in this chapter are meant to give you basic ideas about scripting DEVONthink.

Talking to DEVONthink

In AppleScript you "talk" to programs like DEVONthink using a tell statement, typically referring to an application either by its name, "DEVONthink 4", or its bundle identifier, "com.devon-technologies.think". While these forms will work, we strongly recommend to talk to DEVONthink using the application ID DNtp, as seen in the following statement:

DEVONthink's dictionary

AppleScript-capable applications have their commands, elements, and properties listed in an AppleScript dictionary. DEVONthink includes a large dictionary as a great reference for you. To view the dictionary, open the Script Editor application, select File > Open Dictionary and choose DEVONthink in the appearing window. You can also add DEVONthink to your Script Editor library. Select Window > Library, click the + button and choose DEVONthink. This way you keep DEVONthink's dictionary at hand.

Note: Using the in your script is optional, but including it can make the script seem a bit less robotic. You can also use possessive forms, if they feel more comfortable to you. For example, all the lines in this script are functionally the same:

As noted above, the dictionary is the best place to find specific terminology to be used with DEVONthink.

Again, this isn't a course on AppleScript, but there are a few DEVONthink-specific things you should understand when scripting our application.

Records: Almost every item in a DEVONthink database is a record, a record with properties. Do a search for "record" in the dictionary and you'll see it's a fundamental unit with a wide range of properties associated with it. This means you won't be writing code like, get the second rich text file…. You will be dealing with records with a particular type, in this case rtf.

There are many commands specifically for use with records: create record with, exists record with…, etc. Also note there are some commands that require the term record. For example: move, delete, and convert. You will see a dictionary listing move record, so you can see the command isn't merely move, it's move record.

Parents and Children: Another concept to understand is parents & children. Generally speaking, these classes deal with the container or the contents of some object. The parent of an object is the group containing it. The children of a group are the immediate contents of that group. It does not include the children of sub-groups. Children can be documents or groups; parents can only be groups, tag groups, or RSS feeds.

DEVONthink Windows

While there are standard windows in DEVONthink, it is better to refer to them by their proper classes. A document window (or content window) is a standalone document window. A main window (or viewer window) is a main window. However, they are both subsets of the think window class so it's often useful to use this term to cover either case.

Using Locations

One of the common tasks people want to perform with AppleScript is importing files to a specific group. In order to direct the files to a given location, you need to reference it properly. Below are three general options for choosing a location:

There are many times you want to direct files into a specific group. That group may not be the current group you're in and you may not want to choose a destination each time. Here are two common ways of specifying a particular group in your database to be a destination group in your script:

Working with a selection

Many times you want to process items you have selected in DEVONthink. What class you use depends on the selection.

As a practical example of working with a selection, imagine you want to generate a list of names and dates for use in a document you're working on. Below is a handler commonly seen in DEVONthink scripts: