【发布时间】:2011-08-31 12:43:34
【问题描述】:
我愿意
- 关机
- 重启
- 注销
- 睡觉
我的系统通过我正在制作的应用程序,我似乎找不到任何原生的 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];
}
没有运气
【问题讨论】:
-
技术问答 1134 应该会有所帮助:developer.apple.com/library/mac/#qa/qa1134/_index.html
-
嗨乔希。我实际上发布了第一个问题。完全忘记了。我已经尝试了所有列出的方法,包括没有运气的问答方法
标签: objective-c macos logout shutdown