- 關機
- 重啓
- 註銷
- 睡眠
我的系統通過我提出申請,我似乎無法找到任何本地的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