I'm using i3wm
and I want a script to run after I've unlocked my
screen. I can get this to work when I manually lock my screen,
e.g. using the steps outlined in
this
post.
But I can't get this to work after my screen is automatically unlocked,
e.g. via xautolock
. For example,
xautolock -time 5 -locker "blurlock -n && my_script.sh"
doesn't work – the screen locks after 5 minutes, but the script is not run after unlock. In fact, it doesn't seem to be run at all.
Is there some way to get this to work? Maybe using xss-lock
or
similar?
EDIT
Based on the suggestion by @aviro in the comments, I changed the script to read
#!/usr/bin/bash
echo "Hello" >> $HOME/temp.txt
blurlock -n
echo "Unlocked" >> $HOME/temp.txt
and then ran xautolock -time 1 -locker "my_script.sh &"
. The screen locked, and the file temp.txt
contained both lines from the script. So it is possible to have a command run after unlocking when used in xautolock
.
Part of what I want my script to do is to capture an image from a camera via ffmpeg
. I changed my script to the following:
#!/usr/bin/bash
blurlock -n
ffmpeg -f video4linux2 -s vga -i /dev/video-cam $HOME/Pictures/test.jpg
notify-send -t 30000 'Unlocked'
This works when run manually -- the screen is locked, and after unlocking a notification pops up saying "Unlocked", and an image from the web-cam is written to the file as specified.
But when run via xautolock -locker "my_script.sh"
, after unlocking, there's no image capture or notification. Since I'm running xautolock
from the terminal (and send it to the background with &
), I get the following message
[1] + 581665 suspended (tty output) xautolock -time 1 -locker "my_script.sh"
Adding > /dev/null 2>&1
to the ffmpeg
command doesn't help either.
"blurlock -n && my_script.sh"
(which I don't know if it would work and what is the exit status ofblurlock
, which would determine if the next script runs or not), just create a single script. Inside the script do something at the beginning (write something to file to see that it started running), the next line runblurlock
, and then at the last line write something to a file at the end (you could also add the exit status ofblurlock
). Run this script manually first to see that it works. Then use it as the-locker
and see if it also works whenxautolock
runs it. – aviro Feb 06 '24 at 13:40echo "hello" >> file.txt; blurlock -n; echo "unlocked" >> file.txt
as the-locker
, and the file is written to appropriately. FYI I think this is the script forblurlock
; it is based oni3lock
. – nonreligious Feb 07 '24 at 09:21echo
commands from the script, and put the command I wanted afterblurlock -n
; it's actually a line that usesffmpeg
to take a picture using a webcam. The script works fine when run manually, but when supplied toxautolock
as the-locker
option, nothing happens. I think it might have something to do withstdout=/=stderr
messages, but even adding> /dev/null 2>&1
does not fix this. – nonreligious Feb 07 '24 at 09:21xautolock
from the terminal, it would be launched automatically on login byi3
), but I thought it might give a hint as to where thexautolock
problem originates: maybe there is some output offfmpeg
tostdout
orstderr
that breaks the unlock process. – nonreligious Feb 07 '24 at 17:37my_script.sh &
in your shell. I assume you'll see the same problems. Start by checking which of the 3 lines in the script are causing this to isolate the problem and simplify it. Comment out a line at the time until the problem doesn't appear. Then you'll know it's that specific command and you can be more focused. Then you can submit another new more simplified question that people are more likely to answer, such as: "If I runffmpeg [...] &
in the background, it fails with the message..." (depends if it's actually theffmpeg
or something else). – aviro Feb 07 '24 at 18:00