标签:macos objective-c applescript
在Objective-C里其实也可以运行AppleScript
第一种方式是Source 将脚本写到变量字符串里
NSAppleEventDescriptor *eventDescriptor = nil; NSAppleScript *script = nil; NSBundle *bunlde = [NSBundle mainBundle]; NSString *scriptSource = @"tell application \"Finder\"\r" "display dialog \"test\"\r" "end tell"; if (scriptSource) { script = [[NSAppleScript alloc] initWithSource:scriptSource]; if (script) { eventDescriptor = [script executeAndReturnError:nil]; if (eventDescriptor) { NSLog(@"%@", [eventDescriptor stringValue]); } } }
NSAppleEventDescriptor *eventDescriptor = nil; NSAppleScript *script = nil; NSBundle *bunlde = [NSBundle mainBundle]; NSString *scriptPath = @"/Users/exchen/Documents/test.scpt"; if (scriptPath) { script = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] error:nil]; if (script) { eventDescriptor = [script executeAndReturnError:nil]; if (eventDescriptor) { NSLog(@"%@", [eventDescriptor stringValue]); } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:macos objective-c applescript
原文地址:http://blog.csdn.net/sysprogram/article/details/46817917