Look at my GitHub repository, I have a category of NSAppleEventDescriptor that makes it much easier to create NSAppleEventDescriptor to call different AppleScript procedures with arguments, and coercion to and from many AppleScript typed.
Up vote 0 down vote favorite share g+ share fb share tw.
I would like to know how to execute an applescript from a cocoa application passing parameters. I have seen how easy is to execute applescripts with no parameters in other questions here at stackoverflow, however the use NSAppleScript class, in which, I haven't seen no method that solve my problem. Does anyone have any idea.
I would like a Cocoa code with the same effect o this shell: osascript teste. Applescript "snow:Users:MyUser:Desktop:MyFolder" "snow:Users:MyUser:Desktop:Example:" So it may run this AppleScript. On run argv set source to (item 1 of argv) set destiny to (item 2 of argv) tell application "Finder" to make new alias file at destiny to source 0 end run Any help is appreciated.
Thanks in advance. Cocoa applescript link|improve this question edited Aug 9 '11 at 13:24 asked Aug 5 '11 at 22:02Leandro33429 50% accept rate.
Look at my GitHub repository, I have a category of NSAppleEventDescriptor that makes it much easier to create NSAppleEventDescriptor to call different AppleScript procedures with arguments, and coercion to and from many AppleScript typed. NSAppleEventDescriptor-NDCoercion.
I found easier to follow this piece code. I took a code from here and modified it to my purpose. - (BOOL) executeScriptWithPath:(NSString*)path function:(NSString*)functionName andArguments:(NSArray*)scriptArgumentArray { BOOL executionSucceed = NO; NSAppleScript * appleScript; NSAppleEventDescriptor * thisApplication, *containerEvent; NSURL * pathURL = NSURL fileURLWithPath:path; NSDictionary * appleScriptCreationError = nil; appleScript = NSAppleScript alloc initWithContentsOfURL:pathURL error:&appleScriptCreationError; if (appleScriptCreationError) { NSLog(NSString stringWithFormat:@"Could not instantiate applescript %@",appleScriptCreationError); } else { if (functionName && functionName length) { /* If we have a functionName (and potentially arguments), we build * an NSAppleEvent to execute the script.
*/ //Get a descriptor for ourself int pid = NSProcessInfo processInfo processIdentifier; thisApplication = NSAppleEventDescriptor descriptorWithDescriptorType:typeKernelProcessID bytes:&pid length:sizeof(pid); //Create the container event //We need these constants from the Carbon OpenScripting framework, but we don't actually need Carbon.framework... #define kASAppleScriptSuite 'ascr' #define kASSubroutineEvent 'psbr' #define keyASSubroutineName 'snam' containerEvent = NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite eventID:kASSubroutineEvent targetDescriptor:thisApplication returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID; //Set the target function containerEvent setParamDescriptor:NSAppleEventDescriptor descriptorWithString:functionName forKeyword:keyASSubroutineName; //Pass arguments - arguments is expecting an NSArray with only NSString objects if (scriptArgumentArray count) { NSAppleEventDescriptor *arguments = NSAppleEventDescriptor alloc initListDescriptor; NSString *object; for (object in scriptArgumentArray) { arguments insertDescriptor:NSAppleEventDescriptor descriptorWithString:object atIndex:(arguments numberOfItems + 1); //This +1 seems wrong... but it's not } containerEvent setParamDescriptor:arguments forKeyword:keyDirectObject; arguments release; } //Execute the event NSDictionary * executionError = nil; NSAppleEventDescriptor * result = appleScript executeAppleEvent:containerEvent error:&executionError; if (executionError! = nil) { NSLog(NSString stringWithFormat:@"error while executing script. Error %@",executionError); } else { NSLog(@"Script execution has succeed.
Result(%@)",result); executionSucceed = YES; } } else { NSDictionary * executionError = nil; NSAppleEventDescriptor * result = appleScript executeAndReturnError:&executionError; if (executionError! = nil) { NSLog(NSString stringWithFormat:@"error while executing script. Error %@",executionError); } else { NSLog(@"Script execution has succeed.
Result(%@)",result); executionSucceed = YES; } } } appleScript release; return executionSucceed; }.
I'm not all too familiar with AppleScript, but I seem to remember that they are heavily based on (the rather crappy) Apple Events mechanism which dates back to the days where the 56k Modem was the coolest Gadget in your house. Therefore I'd guess that you're looking for executeAppleEvent:error: which is part of NSAppleScript. Maybe you can find some information on how to encapsulate execution arguments in the instance of NSAppleEventDescriptor that you have to pass along with this function.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.