The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

How to run i3lock after computer inactivity?

asked Jun 7 '12

barchiesi gravatar image

updated Jun 8 '12

I have a script that takes a screenshot of my screen and runs i3lock with that image. Now I would like to know how to start such script after x minutes of inactivity. Ideas?

EDIT: This is the script I'm using when I launch i3lock. It takes a picture then blurs it.

#!/bin/bash
scrot /tmp/screen_locked.png
convert /tmp/screen_locked.png -scale 10% -scale 1000% /tmp/screen_locked2.png
i3lock -i /tmp/screen_locked2.png

4 answers

Sort by » oldest newest most voted
2

answered Jun 16 '14

robru gravatar image

First of all, I just want to say, this is the coolest screen lock I have ever seen in my life. Thanks so much for sharing this idea ;-)

That said, I'm not super comfortable with leaving screenshots lying around in /tmp. Who knows what kind of sensitive info might be on my screen at any given time that the screen lock decides to activate. For security reasons, you should probably use this instead:

#!/bin/sh -e

# Take a screenshot
scrot /tmp/screen_locked.png

# Pixellate it 10x
mogrify -scale 10% -scale 1000% /tmp/screen_locked.png

# Lock screen displaying this image.
i3lock -i /tmp/screen_locked.png

# Turn the screen off after a delay.
sleep 60; pgrep i3lock && xset dpms force off

mogrify modifies the files in place, and is part of ImageMagick, so if you have convert installed, then you already have mogrify.

Also note my use of pgrep and xset for turning the display off after a minute. xset turns the display off, but the pgrep bit makes sure that i3lock is still running before turning the screen off -- this way if you unlock the screen within the first minute, your screen doesn't blink off while you're trying to do something.

Save that to a script, and then a couple lines in .i3/config and you're golden:

bindsym $mod+l exec "~/.local/bin/fuzzy_lock.sh"
exec xautolock -time 15 -locker '~/.local/bin/fuzzy_lock.sh' &

(I like Win+L for locking and I've disabled the jkl; motion keys personally)

Hope this helps!

Comments

Now all I need is a way to visually indicate the screen is about to lock, and a way to abort the locking if a key is pressed....

robru gravatar imagerobru (Jun 16 '14)edit

Scaling to 10% and then 1000% results in a fairly blocky image. Consider using `convert /tmp/screen_locked.png -blur 0x6 /tmp/screen_locked.png` instead. It does however take a few seconds for the image to be generated.

hbaughman gravatar imagehbaughman (Aug 3 '14)edit

Note that "mogrify" takes approximately 2X as long as "convert". I use convert, then remove the original image.

bwv549 gravatar imagebwv549 (Nov 20 '14)edit

To get a more "blocky" feel, I use: ``convert /tmp/screen_locked.png -scale 5% -scale 2000% /tmp/screen_locked.png``

stefanv gravatar imagestefanv (Apr 3 '15)edit

after an incorrect attempt, the screen doesnt turn off after the countdown

airwindh gravatar imageairwindh (Nov 11 '15)edit
1

answered Jun 7 '12

Michael gravatar image

There is a tool called xautolock which is what you’re looking for :).

0

answered Jun 15 '12

Not directly involved with this question, but I thought it might be worth saying, I like the gnome style Ctrl+Alt+L for locking the screen.

You can achieve that in i3 by adding to config file:

bindsym Control+mod1+l exec i3lock

(or, in case your Alt is not mod1, just run xmodmap to get which one to use).

0

answered Jan 23 '13

dkeg gravatar image

updated Jan 23 '13

using the aforementioned xautolock, you could call you script. Place this in you autostart section

exec xautolock -time 10 -locker 'i3lock /path/to/script' &

adjust you time accordingly

Comments

I believe you want exec "xautolock -time 10 -locker 'path/to/script'"

yhager gravatar imageyhager (Apr 1 '14)edit

Question Tools

1 follower

Stats

Asked: Jun 7 '12

Seen: 12,471 times

Last updated: Jun 16 '14