关闭Mac目标C. [英] Shutdown Mac Objective C

查看:193
本文介绍了关闭Mac目标C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够实施以下方法:

I need to be able to implement methods of:


  • 关闭

  • li>
  • 注销

  • 睡眠

我使用XCode,但似乎无法找出代码来执行这些操作。

On a Mac, I am using XCode but can't seem to figure out the code to perform these actions.

任何人都可以帮助我在这里?

Can anyone help me out here?

感谢

推荐答案

一个简单/懒惰的方式是通过一些简单的内联Applescript:

A trivial/lazy way do this is via some simple inline 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); 
}

这篇关于关闭Mac目标C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆