如何在我的 OS X 应用程序中以编程方式 运行 applescript (.scpt)?
How to run a applescript (.scpt) programmatically in my OS X app?
我有一个小的 applescript,我想在我的应用程序中按下按钮后立即 运行 它,我该如何完成?我在 Objective-C.
中制作了这个 OS X 应用程序
NSAppleScript 可以编译和 运行 AppleScripts。
例如,如果您的脚本位于 Resources
文件夹
中的 Scripts
文件夹中
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);
}
}
我有一个小的 applescript,我想在我的应用程序中按下按钮后立即 运行 它,我该如何完成?我在 Objective-C.
中制作了这个 OS X 应用程序NSAppleScript 可以编译和 运行 AppleScripts。
例如,如果您的脚本位于 Resources
文件夹
Scripts
文件夹中
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);
}
}