problem passing a list to an AppleScript function
problem passing a list to an AppleScript function
- Subject: problem passing a list to an AppleScript function
- From: Xavi Caballe Grebol <email@hidden>
- Date: Thu, 1 Dec 2005 00:56:17 -0800
My Cocoa app calls an AppleScript function like this...
on test_function(a_list)
display dialog (length of a_list)
end test_function
To pass a list from Objective-C to the AppleScript function I've
followed the code in...
http://www.cocoadev.com/index.pl?CallAppleScriptFunction
More concretely, here's how I set up the list parameter to send it to
the AppleScript function...
NSAppleEventDescriptor *listDescriptor = [NSAppleEventDescriptor
listDescriptor];
NSArray *listParamElements = [NSArray initWithObjects:@"element1",
@"element2", nil];
int i;
for (i = 0; i < [listParamElements count]; ++i) {
// note that the array starts at index 1
[listDescriptor insertDescriptor:[NSAppleEventDescriptor
descriptorWithString:[listParamElements objectAtIndex:i]]
atIndex:(i+1)];
}
// (...)
[event setParamDescriptor:listDescriptor forKeyword:keyDirectObject];
The problem is that the dialog displayed by test_function shows '5'
instead of '2', so it seems that I'm doing something wrong.
(Mmm... I've just realized... maybe the problem is that I'm not
really passing a list parameter, but a list of parameters? Anyway, if
that's the case, how do I pass a parameter of type list?).
I've also tried to use Ken Ferry's KFAppleScript Handler Additions
with a call like this...
[myTestScpt executeHandler:@"testScript"
withParameters:@"element1",@"element2", nil];
but then the dialog shown by AppleScript displays '9' (instead of '2').
I will be very grateful if someone could shed some light to my problem.
Thanks in advance,
xavi
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden