0

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?

Yes, I asked this question before. I am now on Ubuntu 14.04 and Unity, and the environment has changed. When I run gnome-screensaver-command -q, I get The screensaver is inactive whether the workstation is locked or not. A new environment requires a new answer.

1 Answers1

2

I looked through the packages mentioning unity (apt-cache search unity), ignoring anything with lib, lens, etc. in the name. unity-services caught the eye. One of the files in this package is /usr/share/upstart/sessions/unity-panel-service-lockscreen.conf, an Upstart job containing:

description "Backing Service for the Unity Panel"
author "Andrea Azzarone <andrea.azzarone@canonical.com>"

start on desktop-lock stop on desktop-unlock

respawn exec /usr/lib/unity/unity-panel-service --lockscreen-mode

As you may have guessed, this job is run when the screen is locked. This gives you a couple of options:

Check if the command in the exec line is running:

Check whether /usr/lib/unity/unity-panel-service is running with --lockscreen-mode option. Note that unity-panel-service is always running, but when you lock the screen, another instance is started with that option. So something like:

if pgrep -cf lockscreen-mode
then 
    # do stuff
fi

pgrep -f searches the complete command line, so we can search for the option.

I think in this case the manpage of unity-panel-service is wrong or outdated. It says:

unity-panel-service takes no options.


Use an Upstart job

You can work off the above job configuration to write your Upstart job. Create a session job (say some-job) ~/.config/upstart/some-job.conf containing:

description "Some script to be run when screen gets locked"

start on desktop-lock stop on desktop-unlock

script # do stuff end script

A converse script with the start and stop events swapped can be used to run things when the screen is unlocked.

muru
  • 197,895
  • 55
  • 485
  • 740
  • Am putting the pgrep -cf version into my scripts for now, but setting up the upstart to set something like ~/.is_locked to "true" or "false" and reading that file? I like that. But I'm away from my workstation, so that'll have to wait. – Dave Jacoby Sep 06 '14 at 03:49