Monday, July 27, 2009

Supporting AppleScript in a Cocoa Document-Based App

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!

Monday, July 20, 2009

Beats Traash Aural Reality 18th July 2009

Beats Reality Radio runs every Saturday 7-9 pm. Tune in to 91FM in the Dunedin area, or get the stream online from Radio 1. Haszari, SoNic Smith and guests play plenty of fresh banging fidget, wobble, electro, breaks, house, tech house, and a lot of other stuff.

The show is podcast every week: get it from http://feeds2.feedburner.com/beatsreality. You can subscribe with ease from there. Or just search iTunes store for "energyflash" or "haszari" - free to download/subscribe.

Azymuth & Mark Pritchard - Pieces of Ipanema (Mark Pritchard remix)
The Bulgarian ft. Spoek - Crazy Dog Biscuit (Kink remix)
Hijack - Keep It Real
Devil's Gun - Gold Dust (Boy 8-Bit remix)
Silicone Soul - The Pulse
Dem Slackers - God Is A Slacker (Lee Mortimer remix)
Jesse Rose - Touch My Horn (Mad Kids remix)
Mr Pher - Karma Baby
Digital Manges - Give Me A Reason (Douster remix)
Freeland - Under Control (Alex Metric remix)
Luger Boa - I Need A Girlfriend (Greg Churchill remix)
Angela Fisken - Trash Test
Greg Churchill - Bubblegap
Will Bailey - The Dutty Clem (The Bulgarian mix)
Para-Beats - Hear Diss
Aquasky & Tee Ski - Back To The Top
Aniki - Evil Nugget (Koochie's Bass mix)
SoNic Smith - Ladies Style (Haszari's Le Mans Style remix)
Moby - I Love To Move In Here (Proxy remix)
Bass Weazal - Weazals Love Reggae (Lee Mortimer remix)
Bloc Party - One More Chance (Alex Metric remix)
The Bloody Beetroots - Warp 1.9
Clazziquai Project - Prayers (Shinichi Osawa remix)
The Timelords - Doctorin The Tardis (Dada Life Guerilla Fart #8)

(post originally appeared on http://haszaristwocents.blogspot.com/)

Wednesday, July 1, 2009

Cartoon Beats scores #1 with the first release! (and is available on iTunes)

Yep - SoNic Smith's Ladies Style (Haszari's Le Mans Style remix) is number 1 on Dunedin's Radio 1 Top 11!

So huge thanks to everyone who voted, this is quite unexpected and we really appreciate it.

How far can we take this story? Well if you're elsewhere around the country, or just feel like voting, you can vote for us at any of the bNet/independent stations:
Dunedin / Radio 1:
http://www.r1.co.nz/top11.php
Auck / bfm:
http://95bfm.com/default,top10.sm
Christchurch / RDU:
http://www.rdu.org.nz/music.html
Wellington / Radio Active:
http://www.radioactive.co.nz
Palmy / Radio Control:
http://www.radiocontrol.org.nz/page.php?9
Auck / George:
http://georgefm.co.nz/
Hamilton / Contact:
http://www.contactfm.co.nz/

If you want a piece of the action, you can now buy the EP (or individual tracks) direct from iTunes. So get yours! And.. if you want a freebie, sign up to the mailing list at Cartoon Beats. We'll be sending out regular mailings with news and free exclusive tracks, edits & mixes.

And again, thanks to everyone who's helped us get this far - DJs who played the tracks & demos, wives/partners, radio stations who played our stuff, Radio 1, Rob Vouchermate, people who voted, people who've come see us play... etc. Too many names to list. Thanks!

CBR001 Cover Art
SoNic Smith & Haszari - Cartoon Beats - Ladies Style - the JAcket