Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have lots of stuff in my crontab, including some that talks to my screen. If I'm not there for it to be notifying, I don't really want it to run.

Is there a way I can check to see if the computer is locked, so I can keep it from doing things when I'm not at my desk? Or, alternately, do other things only when I'm not at my desk?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Run this command:

gnome-screensaver-command -q | grep "is active"

if it has any output, the screen is locked.

In a shell script, you can use a clause like this:

if (gnome-screensaver-command -q | grep "is active");
then
    ...
fi

(my thanks to DoR, who originally posted these commands here)

share|improve this answer
2  
When you use grep in a test, its best to use grep -q so that there is no output to the console. Also the parenthesis are redundant - they cause a sub-shell to be created though there's no need for that in this case. –  Guss Apr 15 '11 at 17:39
    
Testing it now to see if I can build on it. It seems to be somewhat fragile and inconsistent in first testing, but that might be just me. –  VarLogRant Apr 15 '11 at 17:41
    
On second thought, it seems to be starting to get together. Thank you. –  VarLogRant Apr 15 '11 at 18:24
    
You don't say "Thank you", but upvote, and mark it as 'accepted answer', when you're nice, please. :) –  user unknown Apr 15 '11 at 19:29
    
But I haven't implemented it enough to accept it as an answer. –  VarLogRant Apr 15 '11 at 19:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.