I ran into an issue developing the latest version of Paperclip (1.4.1 as of this writing) involving applescript. Basically, you cannot send an applescript record to an application. It throws a massive error saying that it can’t convert to the Cocoa equivalent, NSDictionary. To an extend, this isn’t unreasonable. Since dictionaries can basically hold any content and since the keys could be applescript types or keywords (for which there really isn’t any way to translate to Cocoa), it seems prudent to Apple to not allow this.
Unfortunately, that isn’t good enough for me. I wanted better so I wrote it. Paperclip 1.4.1 and later includes an applescript front-end to a Nu parser. This front-end includes the ability to drop objects into the Nu code’s active context by passing a record (hence my need to convert an applescript record into an NSDictionary).
This part of my code, every last usable bit, has been made available as open source. ApplescriptToDictionaryWithNuToo is an example application that demonstrates using applescript as a front-end to Nu.
2 comments on “Turn an Apple Event into an NSDictionary”
has:
April 24th, 2008 at 11:14 am
“It throws a massive error saying that it can’t convert to the Cocoa equivalent, NSDictionary.”
That’ll be Cocoa Scripting; not the brightest bulb in the box.
If you need more extensive AE-Cocoa mappings, objc-appscript’s AEMCodecs class covers all common AE types, including arbitrary records. See http://appscript.sourceforge.net/objc-appscript for more info.
HTH
Grayson:
April 24th, 2008 at 1:16 pm
I think in this case that it’s probably best that Cocoa doesn’t try to convert applescript records to NSDictionaries. There’s so much in applescript that doesn’t have an exact NSObject equivalent, especially when working with scripting additions. I would like Cocoa scripting to at least be able to tell that there are standard objects and try to convert those, but that could lead to confused users if it worked sometimes and didn’t work others. I’m often rather disappointed that there’s no bridge for images.
Thanks for pointing out appscript. I used py-appscript all the time before Leopard’s Scripting Bridge came out. Thanks for the heads up. I’ll look into it.
Leave a Reply