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 2012-06-07 10:23:32 +0000

barchiesi gravatar image

updated 2012-06-08 13:22:48 +0000

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
edit retag flag offensive close merge delete

4 answers

Sort by » oldest newest most voted
2

answered 2014-06-16 04:45:55 +0000

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!

edit flag offensive delete link more

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 ( 2014-06-16 05:04:27 +0000 )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 ( 2014-08-03 16:43:22 +0000 )edit

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

bwv549 gravatar imagebwv549 ( 2014-11-20 15:35:47 +0000 )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 ( 2015-04-03 18:41:46 +0000 )edit

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

airwindh gravatar imageairwindh ( 2015-11-11 12:19:39 +0000 )edit
1

answered 2012-06-07 11:05:36 +0000

Michael gravatar image

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

edit flag offensive delete link more
0

answered 2012-06-15 03:06:29 +0000

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).

edit flag offensive delete link more
0

answered 2013-01-23 14:06:55 +0000

dkeg gravatar image

updated 2013-01-23 14:08:38 +0000

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

edit flag offensive delete link more

Comments

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

yhager gravatar imageyhager ( 2014-04-01 19:48:13 +0000 )edit

Question Tools

1 follower

Stats

Asked: 2012-06-07 10:23:32 +0000

Seen: 12,471 times

Last updated: Jun 16 '14