Aaron Lauterer

Start i3lock on Sleep with SystemD

Ever wondered how to automatically lock your screen when you put your laptop to sleep? Like me you most likely found a SystemD unit file looking a lot like the one below. What annoyed me though was that the lock command would be executed after the system reached the sleep target, ergo when waking up. This resulted in a brief flicker where my screen was visible before i3lock kicked in.

Adding the third line, Before=sleep.target helped to solve that problem.

Description=Starts i3lock at suspend time

ExecStart=<path to your lock script>


Enable it with:

$ systemctl enable screenlock@<username>
Got any hints or questions? blog@aaronlauterer.com