AppleScript Mondays: Let’s Open a dictionary

by Clay Moore on March 8, 2010

in AppleScript Mondays,Computer Language,programming

As much as possible the developers of applescript tried to keep it as much like English as possible. In English we have parts of a sentence, but we also have a dictionary which tells us the meaning of the words. In AppleScript we have the same thing. Each application that wants to be AppleScriptable must expose a list of the things AppleScript can do in something called a Dictionary. After the break we open a dictionary, and see what we can do with it.


Screenshot2010-03-07at5.53.08PM.ESlh0tYoJ82K.jpg

When an App announces that it is AppleScriptable it has to publish a list of things that AppleScript can do to the App. So we need to see the Dictionaries of the apps. Start the AppleScript Editor. Remember that is in the Applications folder under utilities. Then choose File >> Open Dictionary. You will see the dialog above. In my screenshot you may see two of everything. That’s because I have a bootable drive connected to my computer. Find the Finder and select it and click on the choose button.

Screenshot2010-03-07at6.02.35PM.132uE7V5MKQo.jpg

The above screenshot shows the finder dictionary. In the left most. Click on the Standard Suite to see the more common verbs that are part of this suite. What I am interested in is the open verb. See the screen shot below to see the definition of the verb.

Screenshot2010-03-07at6.07.59PM.osNhQz1qrHMd.jpg

For right now the specifier that I want is a folder. So I use he phrase “the folder” to indicate I want to use a folder object. Then I follow that phrase with the name of the folder I want like “Applications”. In this case the name of an object does have the double quotes around it. Because I want to do more than one thing to the Finder I am going to use the Tell … end tell structure. When you tell an application you can use all the phrases from the dictionary of that application when you use the tell … end tell structure. I want my simple script to open the applications folder and have it on top of any other open windows. We use the activate verb for that. So our script looks like this.

Screenshot2010-03-07at6.06.17PM.fMGbSGjCA64S.jpg

The prepositional phrase “of the startup disk” tells AppleScript which mounted volume to use for this open. The order of the operations of this script is the activate and then the open. If you run this script, the finder will come to the top and open a window showing you the applications folder.

Next week we will do something a little more exciting with the Finder.

  • Share/Bookmark

Related posts:

  1. AppleScript Mondays: Extending the Clear Desktop Script
  2. Applescript Monday: Make a Clear Desktop Script
  3. Very Basic AppleScript
  4. Are there any open source replacements for MS Projects?
  5. Using DevonThink as a Super Finder

Previous post:

Next post:

<