Objective-C 运行AppleScript脚本
生活随笔
收集整理的這篇文章主要介紹了
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]);}}}第二種方式是將File, 將腳本寫到文件里 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]);}}}
總結
以上是生活随笔為你收集整理的Objective-C 运行AppleScript脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Objective-C NSFileMa
- 下一篇: Objective-C MacOS以管理