- 在终端更改屏幕保护设置(这个命令要切换到用户态使用)
//不过这个似乎只能设置系统里有的时间才能生效,以s为单位
defaults -currentHost write com.apple.screensaver idleTime 60
defaults -currentHost read com.apple.screensaver idleTime//必须read,不然只有重启才能生效
参考:https://light0457.github.io/2016/08/13/ShadowsocksAutoGrabber/
- 可以从代码中对相应文件下的对应参数进行调整,重启Mac后,屏保相应参数则会对应更新。
文件地址:
~/Library/Preferences/ByHost/com.apple.screensaver.××××××.plist
相关参数:
idleTime 等待时间:指定时间(以秒为单位)后,则会显示屏保程序,设定为0时,则不显示屏保
原文链接:[https://www.cnblogs.com/innovator/p/3958358.html]https://www.cnblogs.com/innovator/p/3958358.html]
3.更改从屏保或睡眠中唤醒是否需要密码,且多久后需要密码
if([systemVersion compare:version] == NSOrderedAscending) {//小于10.13版本
NSString *askForPassword = @"1";
NSString *str1 = @"defaults -currentHost write com.apple.screensaver askForPassword -int ";
str1 = [str1 stringByAppendingString:askForPassword];
NSString *command1 = [NSString stringWithFormat:@"su - %@ -c \"%@\"", userName, str1];
NSArray *arguments1 = [NSArray arrayWithObjects:@"-c", command1, nil];
NSTask *task1 = [[NSTask alloc] init];
[task1 setLaunchPath:@"/bin/sh"];
[task1 setArguments:arguments1];
[task1 launch];
[task1 waitUntilExit];
int st1 = [task1 terminationStatus];
NSString *askForPasswordDelay = @"1";
NSString *str2 = @"defaults -currentHost write com.apple.screensaver askForPasswordDelay -int ";
str2 = [str2 stringByAppendingString:askForPasswordDelay];
NSString *command2 = [NSString stringWithFormat:@"su - %@ -c \"%@\"", userName, str2];
NSArray *arguments2 = [NSArray arrayWithObjects:@"-c", command2, nil];
NSTask *task2 = [[NSTask alloc] init];
[task2 setLaunchPath:@"/bin/sh"];
[task2 setArguments:arguments2];
[task2 launch];
[task2 waitUntilExit];
int st2 = [task2 terminationStatus];
if (st1 == 0 && st2 == 0) {
return YES;
} else {
return NO;
}
}else {
NSString *isNeedPwd = @"true";
NSString *command3 = @"osascript -e 'tell application \"System Events\" to set require password to wake of security preferences to ";
command3 = [command3 stringByAppendingString:isNeedPwd];
command3 = [command3 stringByAppendingString:@"'"];
NSArray *arguments3 = [NSArray arrayWithObjects:@"-c", command3, nil];
NSTask *task3 = [[NSTask alloc] init];
[task3 setLaunchPath:@"/bin/sh"];
[task3 setArguments:arguments3];
[task3 launch];
[task3 waitUntilExit];
int st3 = [task3 terminationStatus];
if (st3 == 0) {
return YES;
} else {
return NO;
}
}
网友评论