[英]Shutdown Mac Objective C
I need to be able to implement methods of: 我需要能够实现以下方法:
On a Mac, I am using XCode but can't seem to figure out the code to perform these actions. 在Mac上,我正在使用XCode,但似乎无法找出执行这些操作的代码。
Can anyone help me out here? 有人可以帮我从这里出去吗?
Thanks 谢谢
A trivial/lazy way do this is via some simple inline Applescript: 这是一个简单/懒惰的方法,通过一些简单的内联Applescript:
NSString *scriptAction = @"restart"; // @"restart"/@"shut down"/@"sleep"/@"log out"
NSString *scriptSource = [NSString stringWithFormat:@"tell application \"Finder\" to %@", scriptAction];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:scriptSource];
NSDictionary *errDict = nil;
if (![appleScript executeAndReturnError:&errDict]) {
NSLog(@"%@", errDict);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.