Skip to content

Instantly share code, notes, and snippets.

@ahwayakchih
Created November 19, 2018 15:28
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 ahwayakchih/6d320d15f509f2452edbf79c9b2c5706 to your computer and use it in GitHub Desktop.
Save ahwayakchih/6d320d15f509f2452edbf79c9b2c5706 to your computer and use it in GitHub Desktop.
Lock screen on Linux with i3lock and Gnome 3
#!/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