I have a code snippet from (unix.stackexchange.com - Run script on screen lock / unlock) which I plan to modify because PulseAudio "undocumented feature" switches sound from TV to laptop when screen is locked.
The code is pretty straight forward:
dbus-monitor --session "type='signal',interface='com.ubuntu.Upstart0_6'" | \
(
while true; do
read X
if echo $X | grep "desktop-lock" &> /dev/null; then
SCREEN_LOCKED;
elif echo $X | grep "desktop-unlock" &> /dev/null; then
SCREEN_UNLOCKED;
fi
done
)
I can't really say I understand the program / subroutine top-down flow or looping but someone from here commented there that it works and I trust his judgement.
The question is what are the naming conventions for my script? What is the industry standard directory to put the script in? How do I invoke it? ie Startup applications, rc.local, cron @reboot, etc. After invocation I trust it runs until the next reboot.
It will be running forever even if it's only used every Wednesday Laundry night so ideally it shouldn't hog too many CPU cycles.