I have a cron script that I want to run regularly if I am logged into my Mac. I don't want it to run if the Lock Screen is up. Is there a way to check from the command line / Terminal if the Lock Screen is activated?
This is the exact implementation I also wanted. After a BUNCH of research, I put this applescript together with contributions from abarnert at http://stackoverflow.com/questions/11505255/osx-check-if-the-screen-is-locked
Now, I know you asked for a terminal check to see if the screen is locked; it's implemented in the code.
I'll point in out here:
If the result of the terminal command:
contains the entry
Then the screen is currently locked. When it does not contain that line, the user is logged in (that is to say, the password has been entered at the lock screen).