我有一个小的applescript,我想在应用程序中按下按钮后立即运行它,如何完成此操作?我已经在Objective-C中制作了这个OS X应用程序。
NSAppleScript可以编译和运行AppleScripts。例如,如果您的脚本位于文件夹Scripts
中的Resources
文件夹中
NSString *compiledScriptPath = [[NSBundle mainBundle] pathForResource:@"myScript" ofType:@"scpt" inDirectory:@"Scripts"];
NSDictionary *error = nil;
NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:compiledScriptPath] error:&error];
if (error) {
NSLog(@"compile error: %@", error);
} else {
[script executeAndReturnError:&error];
if (error) {
NSLog(@"run error: %@", error);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句