As there is this apparent meme about taking pictures on opening a laptop lid, I thought about sharing my little hack for machines running Gnome. Save this somewhere and have it started every time you log in:<p><pre><code> #!/usr/bin/perl
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'\"";
open (IN, "$cmd |");
while (<IN>) {
if (m/^\s+boolean false/) {
`mkdir -p ~/Bilder/snapshots`;
`notify-send -u low -i gtk-orientation-portrait --expire-time=3000 'Smile!' "Taking photo in 3 seconds.\nSaving in ~/Bilder/snapshots/"`;
sleep 3;
my $date="`date +%y.%m.%d-%H:%M`";
`ffmpeg -s 1280x720 -f video4linux2 -i /dev/video0 ~/Bilder/snapshots/$date.jpg 2>&1 >/dev/null`;
}
}
</code></pre>
When I made this a couple of days ago I originally didn't thought about releasing it. It was just a little evening amusement. But maybe somebody finds it amusing as well.<p>A little off topic: I wanted to do this as a shell script originally, but how would one implement the "while read from pipe" part in bash?