The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 2,608     Votes:  5     ✅ Solution
Tags: 16.04   scripts   lock-screen   dbus  
Link: 🔍 See Original Question on Ask Ubuntu 🔗

Title: How do I call `dbus` code that monitors when screen is locked/unlocked?
ID: /2016/12/08/How-do-I-call-_dbus_-code-that-monitors-when-screen-is-locked_unlocked_
Created: December 8, 2016    Edited:  April 13, 2017
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

I have a code snippet from ( - 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
    elif echo $X | grep "desktop-unlock" &> /dev/null; then

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.

⇧ How to disable access to Win7 disk partition(Dual Boot) Trying to Add A Feature to Nautilus  ⇩