Use `xautolock` to run script which captures image with `ffmpeg` after unlocking

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.

Asked By: nonreligious

||

After a lot of experimenting, I’m reasonably sure that using nohup before the ffmpeg command fixes the problem. That is, the above line in my_script.sh should be changed to:

nohup ffmpeg -f video4linux2 -s vga -i /dev/video-cam $HOME/Pictures/test.jpg > /dev/null 2>&1
Answered By: nonreligious
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.