It seemed like it should be easy, and it was, but finding out how was hard. So I am posting what I did here in the hope that the next person wanting to do it finds the info they need here.

What I wanted to do


I had a Cocoa document-based app. I.e. I had followed my nose with Cocoa, and ended up with an app that supported multiple documents. Documents are represented by in subclass of NSDocument called MyDocument.

I wanted to support viewing and changing properties of the document from AppleScript.

Note that I wanted to support 10.5+, so the techniques here may not be appropriate for older versions.

How I ended up getting it working


  1. Specify things in the app's Info.plist:
    NSAppleSriptEnabled = YES

    OSAScriptingDefinition = MyApp.sdef


  2. Made an sdef file, which includes all the framework supplied stuff, and that MyDocument extends the framework document, and has a property, refered to by the key numBananas:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">

    <!-- declare the namespace for using XInclude so we can include the standard suite -->
    <dictionary xmlns:xi="http://www.w3.org/2003/XInclude">

    <!-- use XInclude to include the standard suite -->
    <xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>

    <suite name="MyApp Suite" code="LfMS" description="MyApp application specific scripting facilities.">

    <class-extension extends="document" code="docu">
    <cocoa class="MyDocument"/>
    <property name="number of bananas" code="Bana" type="integer" access="rw" description="The number of bananas in this document" >
    <cocoa key="numBananas"/>
    </property>
    </class-extension>

    </suite>

    </dictionary>

  3. Implement KVC accessors for the property. These looked (sortof) like:
    -(NSNumber*)numBananas
    {
    return [NSNumber numberWithInt:bananas];
    }

    -(void)setNumBananas:(NSNumber*)value
    {
    bananas = [value intValue];
    }



This was all that it took, and now I can enumerate all the docs, set their number of channels etc etc.

Apologies to all my regular readers if this is slightly outside your sphere of interest!
Since the dawn of Mac OS X, new-to-the-platform users have cried "but the font is huge" followed closely by "can I really only choose between blue and grey?"...

I don't have a solution for the second problem, but I have a sorta-solution for the first one, and it got me pretty excited.

I saw a tip on TUAW explaining how to put the date in the menu bar. This got me pretty dang excited because I always refer there, and up til now had to click to get the date. This tip also has the added feature of allowing you to show the date as numbers, which is great, because usually I have to count on my fingers to determine what month it is.

Anyway, back to the point, by having a date format with this guy "/" in, I believe has caused the system font to be bumped down a notch (presumably to accomodate the date in the menu bar), and lemme tellya, it looks so much better. All the system context menus everywhere are using this slightly smaller font, and all the app menu bars too. I'm so pleased, everything is a tiny bit smaller.

Are you worried? I'm not, clearly this is a weird side effect that could disappear at any moment, and still only gives you one other font size choice (oh, and I haven't tried switching back, maybe it's broken forever). BUT how great does it feel to make a 0.5-point (estimated) change to the Mac OS X system font?


FORKING INCREDIBLY GREAT.