I am new to the world of Cocoa programming, and I want to add Applescript support to my application. The examples at Apple\'s website seem out of date.
How do I add
A simple example to get you started,
place a script (named dialog) into the documents folder then you can run it from Xcode
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [arrayPaths objectAtIndex:0];
NSString *filePath = [docDirectory stringByAppendingString:@"/dialog.scpt"];
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filePath] error:nil];
[scriptObject executeAndReturnError:nil];
The nice thing about keeping the script external is the ability to edit it outside of Xcode. I would recommend adding the error checking if you did start editing as the applescript may not compile
maybe check with
if(scriptObject.isCompiled){