Making your own AppleScript dictionaries

In this tutorial, I'll explain how to make your own AppleScript suites for your SuperCard standalones. By default, standalones has a minimal script dictionary, with the commands 'do script' and 'evaluate'. However, you might want to define your own commands, because allowing a user to run any script might not be very elegant.

AppleScript communicates using AppleEvents, so every time a command is run from a script controlling your application, the app receives an AppleEvent. Fortunately, a convenient message is sent to the project every time SC receives an AE. Different AppleScript commands sends AppleEvents with different ID's.

So what we should do first is to script the events inside SuperCard. So make a new project and make two card fields. Then enter its project script and enter the script displayed below.


A SC project with two card fields.


The script of the project.

Okay, so we're done making the project. Close it and build a standalone of it. Now we'll need some kind of resource editor that supports editing 'aete' resources. I recommend ResFool. It's shareware, so if you use it much, you should buy it.

Open your standalone with ResFool, and open the 'aete' resource named "SuperCard Terminology" (well, there's only one anyway).


Edit the resource by double-clicking the line titled "SuperCard Terminology".

A large window should now open. Click the Suite popup menu at the top. You'll see two items, 'required' and 'SuperCard Misc'. An AppleScript Suite is a group of commands (and classes), and we're going to make a new one. Click the Edit button to the right of the popup menu. A sheet will drop down. Click the Add button and enter a name for the new suite ('Test Suite' maybe). Type in 'MyAp' (without the quotes) in the Code field, and put 1 into the Level and Version fields. Click Done when you're done.


The Suite popup menu.


Making a new AppleScript Suite.

Now, we're going to add some commands to the new suite. Select the suite you just created from the Suite menu, and click the 'Add' button. Name this command 'first test' (without the quotes). Set its ID to 'Cmd1' (notice how this corresponds with the IDs we wrote in SC!). The class should already be set to 'MyAp'. Now, go to the 'Direct Paramater' part of the window (top right). Instead of 'null', enter 'TEXT' (without the quotes) into the Type field. Write something like 'field contents' in the large field below the Type field. Now add one more command, but name it 'second test' and set its ID to Cmd2. The window should now look like the one shown below.


The window after having added two commands.

So we're basically done, so save and close the file. Let's test if it works! Drag your standalone app to the Script Editor app (Applications:AppleScript:) to view its dictionary. You should see the new test suite in the list to the left. Make a new script and enter the script below. You probably have to replace 'AS Test' with the name of your standalone.


The script.

Try clicking the Run button to test the script. It everything goes right, it should put some text into the first field of your standalone. Also try 'second test'. Good luck AppleScripting!

© 2004 Tomas Franzén
tomas@lightheadsw.com