macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Integrating AppleScript and Cocoa
Pages: 1, 2, 3, 4

Back in the project window, you should now see, in the Resources folder, the ScriptableDocApp.scriptSuite file and the ScriptableDocApp.scriptTerminology file. If you select either one, you should see the XML in the editor window. Now, we need to localize the scriptTerminology file, so select the ScriptableDocApp.scriptTerminology file and from the Project menu choose "Show Info."

Screenshot
The Info window for ScriptableDocApp.scriptTerminology

In the info window that appears, you should see the ScriptableDocApp.scriptTerminology file listed in the Name field and on the right there is a drop-down menu that says "Localization & Platforms." Select "Make Localized" from this menu, and you'll see an expansion arrow appear next to the file name in the Resources folder. From the same "Localization & Platforms" menu, choose "Add Localized Variant..." and in the panel that appears, click on the right arrow and select "English." You could also just type "English" into the panel.

Screenshot
Adding an English localized variant of our ScriptableDocApp.scriptTerminology file.

Click on the OK button and then you can close the Info window.



Choose Build and Run from the Build menu, saving any files that need it.

Try running the script again from the Script Editor, and you should now see a new document window being created each time the script runs. If you have any trouble, you can download my ScriptableDocApp project file here.

One other interesting thing you can try is to play with the script Terminology file. If you change "document" to be "my document," and "documents" to be "my documents" in the ScriptableDocApp.scriptTerminology file and then save and rebuild your application, you will change the manner to which the MyDocument class is referred. To see this, you will need to quit out of the Script Editor application, because it will cache the older version of the terminology from ScriptableDocApp until you do, and then restart Script Editor and paste in this script:


tell application "ScriptableDocApp" 
	activate 
	set w to make new my document at the beginning of my documents 
	--close every document 
end tell

Run it, and you should see it work the way it did before, but now with new terminology. You can also look at the ScriptAbleDocApp's script dictionary to see how the terminology changes. One thing to be careful of when changing the script Suite or Terminology files is that Script Editor will need to be restarted in order to get the latest verison of both files. You can save your scripts as text files to save them between restarts. It is a pain, but keep in mind that the syntax and terminology for your applications won't often change, so caching is generally a good idea.

One other gotcha I have run into is that if you Clean the project, the NSAppleScriptEnabled key will be removed from the Info.plist file. You can simply add this back in after cleaning, so if you suddenly find your application is not responding to scripting at all, check to see if Info.plist has been changed.

Next Time

We are going to continue adding support for the Core Suite in ScriptableDocApp, including adding some text and the ability to load, save, and print our documents. This will mean jumping into ObjC and writing some code, so if you are not familiar with the basics of ObjC, check out Mike Beam's column or some of the tutorials that come with the Apple developer tools.

See you then.

Brad Dominy is the head of Neoki, LLC, a small web design firm located in Chicago, IL.


Return to the Mac DevCenter.