Chris Redford
Chris Redford

Reputation: 17778

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 -C $FILENAME

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

Upvotes: 5

Views: 4264

Answers (3)

Dmitry Ulupov
Dmitry Ulupov

Reputation: 311

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

Upvotes: 12

shoover
shoover

Reputation: 3130

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.)

Upvotes: 1

Fortega
Fortega

Reputation: 19682

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 :)

Upvotes: 2

Related Questions