我需要能够实现以下方法:
- Shutdown
- Restart
- Logoff
- Sleep
在 Mac 上,我使用 XCode,但似乎无法找出执行这些操作的代码。
有人可以帮我从这里出去吗?
Thanks
一个简单/懒惰的方法是通过一些简单的内联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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)