开发者

Check if Screensaver is Active using Mac Bash Script Command

I've found many useful Bash commands that can execute OS X behaviors from the command line such as:

screencapture -x 开发者_如何学JAVA-C $FILENAME

Is there such a command that can check if the screen saver is active?


I am using this:

ps ax|grep [S]creenSaverEngine > /dev/null
if [ "$?" != "0" ] ; then
    # screen saver is not active
else
    # screen saver is active
fi


the screensaver in Mac is just an application, so possibly you could check if the process is running...

I think the process is named 'ScreenSaverEngine', but I'm not sure if this is true for the version you have :)


My Mac is at home and I'm not, so I can't test this solution, but how about something like:

ps -ef | grep [s]creencapture > nul; echo $?

The [] brackets prevent grep from matching this grep command while allowing it to match all other commands containing "screencapture". (Assuming "screencapture" is the name of the process you're trying to detect.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜