I’ve embedded an AppleScript into my Xcode project. The script processId.scpt requires an argument. How can I add this when executing the script in Objective-C?
NSString *scriptPath = [[NSBundle mainBundle] pathForResource:@"processId" ofType:@"scpt"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:scriptPath]) {
NSURL *scriptUrl = [[NSURL alloc] initWithString:scriptPath];
NSDictionary *error = nil;
NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL:scriptUrl error:&error];
NSAppleEventDescriptor *result = [script executeAndReturnError:nil];
NSData *data = [result data];
int pid = 0;
[data getBytes:&pid length:[data length]];
NSLog(@"Result: %d. %@. %@.", pid, [result stringValue], [error description]);
}
I’m not sure how you’re taking arguments in the script, but take a look at this post for info about creating an
AEMEvent, attaching parameters to it, and then sending it to the script.