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 <[email protected]>"
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.