Re: AppleScript Record and NSDictionary
Re: AppleScript Record and NSDictionary
- Subject: Re: AppleScript Record and NSDictionary
- From: Jim Correia <email@hidden>
- Date: Tue, 21 Jul 2009 20:36:40 -0400
On Jul 21, 2009, at 6:51 PM, Steve Cronin wrote:
From my Cooca app I want to call an AppleScript with several
parameters one of which is an AppleScript record.
[...]
When I look at the docs for -recordDescriptor and I see the 4
character code business - I get the ugly sinking feeling but maybe
that's the only way...
I've tried to move the coercion into AppleScript but there is
nothing that will do that except the magic 'user record fields'.
But there are warnings about resouce use for the 'magic' values....
(And anyway while seated in front of this machine, I don;t really
like magic!!)
- (NSAppleEventDescriptor) coerceDictionary(NSDictioanary
*)dictionary {
NSAppleEventDescriptor *result = [NSAppleEventDescriptor
recordDescriptor];
NSArray *keysArray = [dictionary allKeys];
NSArray *valuesArray = [dictionary allValues];
unsigned int keyCoount = [keysArray count];
for ( i = 0; i < keyCount; i++) {
//the good stuff happens here....
}
return result;
}
So is there an exprienced soul out there who might share a snippet
of code or a an illuminating link?
Since you omitted "// the good stuff happens here" it isn't clear to
me what, if anything, you've already tried.
An AE record is keyed by four character codes. There is a special key
- keyASUserRecordFields - which is an AEList of sequential keys and
values. When this is present in the record, these appear as string
keys to AppleScript.
So, create an AE record, and add an appropriate list to the record
with the key of keyASUserRecordFields. Whether you write this code
using the C API or the Foundation NSAppleEventDescriptor API is now
just an implementation detail :-)
Jim
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden