Fastest lock screen using i3lock

Fastest lock screen using i3lock

This is probably the fastest bash script you have ever seen that:-

  • Takes a screenshot of your desktop
  • Blurs it
  • Locks your screen

All of this in under a second!

The script

#!/bin/bash
PICTURE=/tmp/i3lock.jpg
SCREENSHOT="scrot --silent $PICTURE"
$SCREENSHOT
convert -scale 10% -blur 0x0.5 -resize 1000% $PICTURE $PICTURE
pkill i3lock
i3lock -i $PICTURE
rm $PICTURE

How the script works

The following was generated by chatGPT
This is a Bash shell script that takes a screenshot of the current desktop, applies a blur effect to it, sets it as the lock screen wallpaper, and then removes the temporary screenshot file. Here’s a breakdown of what each line does:

#!/bin/bash

This is known as the shebang line, which tells the system that this script should be run using the Bash shell.

PICTURE=/tmp/i3lock.jpg

This sets the variable PICTURE to the file path /tmp/i3lock.jpg.

SCREENSHOT="scrot --silent $PICTURE"

This sets the variable SCREENSHOT to the command scrot —silent /tmp/i3lock.jpg, which takes a screenshot of the desktop and saves it to the file specified by PICTURE. The —silent option makes scrot run silently without any visible output.

$SCREENSHOT

This executes the scrot command stored in the SCREENSHOT variable.

convert -scale 10% -blur 0x0.5 -resize 1000% $PICTURE $PICTURE

This applies some image processing effects to the screenshot stored in $PICTURE. Specifically, it scales the image down to 10% of its original size, applies a blur effect with a radius of 0.5 pixels, and then scales it back up to 1000% of its original size. The result is a blurred version of the original screenshot, which is then saved back to $PICTURE.

pkill i3lock

This kills any running instances of the i3lock program, which is the program responsible for locking the screen.

i3lock -i $PICTURE

This runs the i3lock program with the -i option to specify the image file to use as the lock screen wallpaper.

rm $PICTURE

This removes the temporary screenshot file from the /tmp directory.

JPG seems to be the fastest format (its almost 2 seconds faster than PNG)


← Back to blog