- 关机
- 重启
- 注销
- 睡眠
我的系统通过我提出申请,我似乎无法找到任何本地的Objective C方式来做到这一点,这非常困难。
任何人都可以指导我做到这一点的最好办法:
我曾尝试:
NSString *scriptAction = @"restart"; // @"restart"/@"shut down"/@"sleep"/@"log out"
NSString *scriptSource = [NSString stringWithFormat:@"tell application \"Finder\" to %@", scriptAction];
NSAppleScript *appleScript = [[[NSAppleScript alloc] initWithSource:scriptSource] autorelease];
NSDictionary *errDict = nil;
if (![appleScript executeAndReturnError:&errDict]) {
//
}
那没有运气可言,也试过:
NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:
@"Tell application \"Finder\" to restart"];
if (theScript != NULL)
{
NSDictionary* errDict = NULL;
// execution of the following line ends with EXC
if (YES == [theScript compileAndReturnError: &errDict])
{
[theScript executeAndReturnError: &errDict];
}
[theScript release];
}
由于没有运气
可能重复[Shutdown Mac Objective C](http://stackoverflow.com/questions/4505632/shutdown-mac-objective-c) – 2011-05-23 23:03:56
技术问答1134应该会有帮助:http://developer.apple.com /library/mac/#qa/qa1134/_index.html – 2011-05-23 23:08:44
嗨乔希。我实际上发布了第一个问题。完全忘了它。我已经尝试了所有列出的方法,包括没有运气的q&a – 2011-05-23 23:19:11