Re: AppleScript Record and NSDictionary

2009-07-22 Thread has

Steve Cronin wrote:


From my Cooca app I want to call an AppleScript with several
parameters one of which is an AppleScript record.

I've got everything about calling and return values working smoothly.

What I can't seem to get is how to create that parameter record.


ObjC-appscript's AEMCodecs class provides two-way mappings between  
NSDictionaries and other common Foundation classes and their  
NSAppleEventDescriptor equivalents. There's also an example project in  
the svn repository showing how it can be used in conjunction with  
NSAppleScript. When specifying record keys in your NSDictionary, use  
AEMType instances to signify AppleScript-defined property names, and  
NSStrings for user-defined identifiers.


HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: AppleScript Record and NSDictionary

2009-07-21 Thread Jim Correia

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com