Results 1 to 2 of 2

Thread: How to know when screen is locked/unlocked in ubuntu 17.10

  1. #1
    Join Date
    Sep 2009
    Beans
    4

    How to know when screen is locked/unlocked in ubuntu 17.10

    I have try to ask this also in stackoverflow but I am not able to achieve nothing:

    https://askubuntu.com/questions/974199/how-to-run-a-script-at-screen-lock-unlocks-in-ubuntu-17-10?noredirect=1#comment1562164_974199


    I want to run an script on screen lock and another one on unlock... How can I know when this occurs?

    I've try using dbus-monitor


    #!/bin/bash

    dbus-monitor --session "type='signal',interface='org.gnome.ScreenSave r'" | \
    ( while true
    do read X
    if echo $X | grep "boolean true" &> /dev/null; then
    echo "locking at $(date)" >> $HOME/time_xprofile
    elif echo $X | grep "boolean false" &> /dev/null; then
    echo "unlocking at $(date)" >> $HOME/time_xprofile
    fi
    done )

    But doesn't work; that signal often doesn't appear at all (neither true nor false)

    And also I have try to find which process is running while screen is locked which is not running while unlocked. So I could use 'ps' command to know when it happens using this script with that procname (seems that is not 'gnome-screensaver-dialog')

    #!/usr/bin/env python3
    import psutil
    import time
    import subprocess

    procname
    ="gnome-screensaver-dialog"
    lock_command
    ="/path/to/lockscript"
    unlock_command
    ="/path/to/unlockscript"

    lock1
    =None

    while True:
    --time
    .sleep(2)
    --lock2
    = procname in(p.name()for p in psutil.process_iter())
    --if lock2 != lock1:
    ----if lock2:
    ------subprocess
    .Popen(lock_command)
    ------print("locked")
    ----else:
    ------subprocess
    .Popen(unlock_command)
    ------print("unlocked")
    --lock1
    = lock2

    But I cannot find any new process while locked... the only process that I see relevant is gsd-screensaver-proxy, which is allways running...

    So, I cannot find a way to do it.

    How can I know when the screen flips to locked/unlocked in ubuntu 17.10 with xserver and ubuntu-gnome?
    Last edited by inigoD; November 8th, 2017 at 11:33 PM.

  2. #2
    Join Date
    Dec 2009
    Beans
    13
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: How to know when screen is locked/unlocked in ubuntu 17.10

    I too am trying to figure out how to run a command on screen lock and unlock. Have you made any progress?

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •