且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何检测屏幕被锁定或屏幕保护程序激活从终端在OS X 10.6?

更新时间:2023-11-14 12:31:58

通过苹果事件一个杂牌的一点,但您可以轻松地查询系统活动后台应用告知如果屏幕保护程序正在运行。例如:

A bit of a kludge but you can easily query the System Events background app via Apple Events to tell if a screen saver is running. For example:

$ osascript -e 'tell application "System Events"' \
>  -e 'get running of screen saver preferences' \
>  -e 'end tell'
false
$ # engage screen saver after starting next command
$ sleep 5; osascript -e 'tell application "System Events"'  -e 'get running of screen saver preferences'  -e 'end tell'
true
$

您可能真的需要找出为什么你要锁起来,虽然。

You probably really need to find out why you're getting the lock up, though.