CocoaDev

Edit AllPages

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSAppleScript_Class/index.html

NSAppleScript is a great tool in inter-application communication.

It can execute raw AppleScript code, compiled AppleScript code and AppleEvents. It can then return anything that has been generated in the external code.

Some hints:

Sample source code:

NSAppleScript *playScript; playScript = NSAppleScript alloc] initWithSource:@”beep 3”]; [playScript executeAndReturnError:nil];

NSString *scriptPath = [[NSBundle mainBundle] pathForResource: @”your_script” ofType: @”scpt” inDirectory: @”Scripts”]; NSAppleScript *theScript = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: scriptPath] error: nil];

*[[KFAppleScriptHandlerAdditions


The AppleScript Language Guide:

http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/index.html


Note that NSAppleScript is pretty much superseded by ScriptingBridge in Mac OS X 10.5 Leopard. ScriptingBridge is much easier to use, however it is only available to Leopard apps.


Not entirely true: NSAppleScript is still recommended for executing user-supplied scripts within your application (what AppleScripters call ‘attachability), c.f. System Events’ folder actions, Mail’s ‘run AppleScript’ rule action, etc.

Users wanting to send Apple events directly from ObjC might also consider ObjCAppscript, which provides significantly better application compatibility than ScriptingBridge and works on Mac OS X 10.3.9 and 10.4.x as well. – hhas