Last active
July 26, 2024 16:30
-
-
Save ameenross/e2ef81485dc3237c0da08e9663d69795 to your computer and use it in GitHub Desktop.
Log Gnome login/logout and lock screen events
This file contains 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
[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= |
This file contains 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 | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The actual filename for the
.desktop
file should be.config/autostart/lockScreen.sh.desktop
.