Created
November 19, 2018 15:28
-
-
Save ahwayakchih/6d320d15f509f2452edbf79c9b2c5706 to your computer and use it in GitHub Desktop.
Lock screen on Linux with i3lock and Gnome 3
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/sh -e | |
if [ `ps -u $USER | grep -Ec "(i3lock|totem|mpv|vlc|*mplayer)"` -gt 0 ]; then | |
exit | |
fi | |
i3lock -c 333333 -i ~/Pictures/Wallpapers/screenlock.png -f; | |
function get_idle_time() { | |
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Mutter/IdleMonitor/Core --method org.gnome.Mutter.IdleMonitor.GetIdletime | sed -r 's/.*uint64 *([0-9]+).*/\1/g'; | |
} | |
monitorOff=0 | |
idleMillisecondsLimit=5000 | |
while true; do | |
pgrep i3lock >/dev/null || exit; | |
idleMilliseconds=`get_idle_time`; | |
if [ "$idleMilliseconds" -ge "$idleMillisecondsLimit" ] && [ "$monitorOff" = "0" ]; then | |
xset dpms force off; | |
monitorOff=1; | |
elif [ "$idleMilliseconds" -le "$idleMillisecondsLimit" ] && [ "$monitorOff" = "1" ] ; then | |
monitorOff=0; | |
fi | |
sleep 1; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment