macos 如何从 os x 终端启动屏幕保护程序(并锁定屏幕)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4505198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:28:54  来源:igfitidea点击:

how can i start the screensaver (and lock the screen) from the os x terminal?

macos

提问by dan

Is there a way to start the screensaver (and lock the screen) from a bash script?

有没有办法从 bash 脚本启动屏幕保护程序(并锁定屏幕)?

回答by yurymik

Have you tried this?

你试过这个吗?

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine

Update for macOS High Sierra:

macOS High Sierra 更新:

/System/Library/CoreServices/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine

回答by rouble

Here is a bash script that does exactly what you are asking for: maclock

这是一个 bash 脚本,它完全符合您的要求:maclock

It is called from the command line as follows:

它是从命令行调用的,如下所示:

maclock

Under the covers it calls:

在幕后,它调用:

open -a ScreenSaverEngine

It can also be used to mute the system, or put the display to sleep:

它还可用于使系统静音,或使显示器进入睡眠状态:

maclock --mute --display