Skip to content

Instantly share code, notes, and snippets.

@ameenross
Last active June 3, 2022 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ameenross/e2ef81485dc3237c0da08e9663d69795 to your computer and use it in GitHub Desktop.
Save ameenross/e2ef81485dc3237c0da08e9663d69795 to your computer and use it in GitHub Desktop.
Log Gnome login/logout and lock screen events
[Desktop Entry]
Type=Application
Exec=./lockScreen.sh lock_screen.log
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en]=Log lock screen events
Name=Log lock screen events
Comment[en]=
Comment=
#!/bin/bash
outputFile=${1:-/dev/stdout};
dateFormat=${2:-[%F %T]};
exitReport() {
echo "$(date +"$dateFormat") Monitoring Terminated." >> $outputFile;
exit;
}
trap "exitReport" 0;
addDate() {
found=0;
locked=0;
while IFS= read -r line; do
# If the line ends with ActiveChanged, next line is true/false.
if [[ $line == *'ActiveChanged' ]]; then
found=1
continue;
fi;
if [[ $found == 1 ]]; then
if [[ $line == *'true' ]]; then
if [[ $locked == 0 ]]; then
echo "$(date +"$dateFormat") Screen Locked";
fi;
locked=1;
else
if [[ $locked == 1 ]]; then
echo "$(date +"$dateFormat") Screen Unlocked";
fi;
locked=0;
fi;
fi;
found=0;
done;
}
echo "$(date +"$dateFormat") Monitoring Started." >> $outputFile;
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | addDate >> $outputFile &
wait;
echo "$(date +"$dateFormat") Script Ended." >> $outputFile;
@ameenross
Copy link
Author

The actual filename for the .desktop file should be .config/autostart/lockScreen.sh.desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment