Created
February 9, 2020 07:50
-
-
Save Hashbrown777/6e1c6b4f9191788d0f794438f5c49bbd to your computer and use it in GitHub Desktop.
outputs "Locked" & "Unlocked" + `date` every time the [fedora+plasma] machine's screen is locked/unlocked. Add to startup script like `nohup lockMonitor.sh >>locklog.txt &`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#prints out, among other things; | |
# string "org.kde.screensaver" | |
#transform it to 'org.kde.screensaver' | |
service=$(\ | |
dbus-send \ | |
--session \ | |
--dest=org.freedesktop.DBus \ | |
--type=method_call \ | |
--print-reply \ | |
/org/freedesktop/DBus org.freedesktop.DBus.ListNames \ | |
| grep -o '[^"]*.screensaver' | |
) | |
#prints out, among other things; | |
#method bool org.freedesktop.ScreenSaver.SetActive(bool e) | |
#transform it to 'org.freedesktop.ScreenSaver' | |
interface=$( | |
qdbus \ | |
$service /ScreenSaver \ | |
| grep -oP '[^ ]*(?=.SetActive)' | |
) | |
path='/ScreenSaver' | |
#monitor it with a while loop | |
dbus-monitor "type='signal',interface='$interface',member='ActiveChanged',path='$path'" \ | |
| while read -r line; do | |
#ignore the metadata and pull the 'boolean <true/false>' line | |
read line | |
#check if it is set to true | |
if echo $line | grep -q 'true'; then | |
echo "Locked at $(date)" | |
else | |
echo "Unlocked at $(date)" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment