Having defined an AppleScript with a method
on stringMethod(theString)
display alert theString
end stringMethod
then in x-code, I am following Technical Note TN2084
http://mirror.informatimago.com/next/developer.apple.com/technotes/tn2006/tn2084.html#TNTAG10
to load the script:
NSAppleScript* appleScript =
[[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
The code below from TN2084 shows how to pass the string parameter:
// create the first parameter
NSAppleEventDescriptor* firstParameter =
[NSAppleEventDescriptor descriptorWithString:@"Message from my app."];
// create and populate the list of parameters (in our case just one)
NSAppleEventDescriptor* parameters = [NSAppleEventDescriptor listDescriptor];
[parameters insertDescriptor:firstParameter atIndex:1];
......
and then fix things up to finally run the AppleScript method to display the string:
// call the event in AppleScript
if (![appleScript executeAppleEvent:event error:&errors]);
{
// report any errors from ‘errors’
}
[appleScript release];
My question is, how would I change this to support passing an NSDictionary as the single parameter so I can something like:
NSDictionary *testDict = @{@"FirstName": @"Joe", @"LastName": @"Smith", @"Age": @27};
into an AppleScript like:
on recordMethod(theRecord)
display alert FirstName of theRecord
display alert (Age of theRecord as text)
end recordMethod
There is no analogous method 'descriptorWithDictionary: ’ for a dictionary parameter initialization. Evidently, you have to use something like:
NSAppleEventDescriptor descriptor
and then fill in the contents of the NSAppleEventDescriptor based on the fields of the NSDictionary.
So this is where I am stuck. I am assuming that if I can build ‘firstParameter’ correctly to mirror the NSDictionary,
then the code that follows will just work, even though the parameter must be structured in AppleScript as a Record instead of the example code using a String.
Thanks in advance for any hints.