Living on Linux

A simple lockscreen script

My main machine is a laptop, which means I take it with me to places outside my home. I used to just switch to an empty workspace when I had to get up and leave the device for a bit because most people don't have a clue how to navigate a window manager without a bar. This is called security through obscurity, and it's not really a safe way to "lock" your device.

Another issue with this is that it would leave my screen on for no reason if I didn't close the lid. Now the simplest way to solve this issue is obviously closing the lid, but that would disconnect the wifi. Usually at school, I would have something running that I needed an internet connection for, so that was not an option.

Therefore I decided I needed a proper lock screen and I wanted it to also turn off my display when locked, but I couldn't find a lockscreen application that had this behavior. So, I did the Linux-y thing and scripted it with the following super simple script requiring only two programs to run: xset and slock.

#!/usr/bin/env bash

# Lockscreen 1.0
# Locks the screen and turns off the display
# Dependencies: xset slock
# By Joris van Dijk |
# Licensed under the GNU General Public License v3.0

( slock && xset dpms 0 0 0 ) &
xset dpms 0 0 2

In a nutshell, this script lock the screen and turns the display off after two seconds. When you enter the correct password, the screen is unlocked and the display time out is disabled, meaning the screen will never turn off after any amount of inactivity.

And that's it! As always the latest version of this script can be found in my dotfiles!