Turning Off Mac Goal C

I need to be able to implement methods:

  • Shutdown
  • Restart
  • Logoff
  • Sleep

On Mac, I use Xcode, but I canโ€™t understand the code to complete these steps.

Can anyone help me here?

thanks

+4
xcode cocoa shutdown macos
source share
1 answer

A trivial / lazy way to do this through some simple built-in 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); } 
+10
source share

All Articles