Webcam snapshot on login and unlock (Ubuntu 10.10)
And this is why I love GNU/Linux: with a few minutes and the Internet, I've just hacked up a way to take a webcam snapshot every time I login and unlock the PC. The best way to keep track of Movember, if nothing else!
First I created a script to take the snapshot and put it in ~/.local/bin/faces/take-snapshot.sh
#!/bin/sh# Take a snapshot with the webcamMYDIR="$( cd "$( dirname "$0" )" && pwd )"
BASEFILENAME="$MYDIR/`date +%Y-%m-%d-%T`"
JPEGFILE="$BASEFILENAME.jpeg"
JPGFILE="$BASEFILENAME.jpg"
PNGFILE="$BASEFILENAME.png"
# Say cheese!streamer -o $JPEGFILEmv $JPEGFILE $JPGFILErm $MYDIR/latest.jpgln -s $JPGFILE $MYDIR/latest.jpg# Create a dot face filerm $MYDIR/*.png 2> /dev/nullconvert -crop 200x200+0+0 -gravity Center -resize 128x128 $JPGFILE $PNGFILErm ~/.facecp $PNGFILE ~/.face
Test that a few times -- yep, I'm getting a jpeg in the faces directory, converting (and cropping) to a PNG for the dot-face file used by GDM. This uses the program "streamer" (in the Ubuntu repositories), but you could probably find some other webcam snapshot app if streamer doesn't work for your webcam (it is V4L2 only, I think).
Next, I script the GDM login. GDM already has some scripts that it runs at particular points in the login, so I just extend that. Edit /etc/gdm/PreSession/Default (as root) and add:
if [ -x $HOME/.gdm/PreSession/Default ];
thensudo -u $USER $HOME/.gdm/PreSession/Default >> /var/log/boo.log
fi
This extends the GDM scripts to also execute user-specific scripts in my home directory. In my case, I add a script called ~/.gdm/PreSession/Default containing:
$HOME/.local/bin/faces/take-snapshot.sh
Yep, calling the take-snapshot.sh script. chmod u+x ~/.gdm/PreSession/Default and login and a couple of times to make sure it is working -- each time a new picture should be taken, so check the ~/.local/bin/faces directory to make sure.
All that's left is to capture the gnome-screensaver deactivation, and a little Perl script comes to the rescue. Create a file screensaver-watch.pl in the ~/.local/bin/faces directory:
Yep, this watches DBUS for the gnome-screensaver signal, and runs take-snapshot.sh again. (You'll need to edit -- it's got my home dir hardcoded.)
Final step is to make sure screensaver-watch.pl is started on every login. The easiest way I could think of was to create a file called Screensaver Snapshot.desktop in ~/.config/autostart with the following contents:
[Desktop Entry]
Version=1.0
Type=ApplicationTerminal=false
Icon[en_US]=eog
Exec=/home/glennji/.local/bin/faces/screensaver-watch.pl
Name[en_US]=Screensaver Snapshot
Name=Screensaver SnapshotIcon=eog
(Again, hardcoded paths. Some things are too important to do the right way after all.)
Logout, login, check the dir, lock screen, unlock and check again. Woooo!
