I just switched from a MacBook Pro to a Lenovo ThinkPad, where I had Ubuntu installed. Switching OS is not too much of a problem, as I am already used to Ubuntu from before. What’s causing more irritation is the new input devices, i.e. the trackpad and the keyboard.
One of the more annoying features is the overly accessible Print Screen key, positioned right between AltGr and Ctrl. I have accidentally pressed it at least three times during the last few days, which on Ubuntu triggers a camera shutter noise and a dialog for the newly captured screenshot. It’s easy enough to ignore it and learn to simply press Esc and continue working, but I decided to do something more fun about it: When the key is pressed, take a photo with the webcam.
Howto: Re-map the Print Screen key to take a webcam photo on Ubuntu
sudo apt install fswebcam
Figure out the fswebcam command you want to use. Try it out in the terminal. You may want to increase the resolution (the default is 384×288) and skip a few frames during which the camera adjusts to the light conditions.
fswebcam -r 640x480 --jpeg 85 -S 3 face.jpg
Create a simple script to save the output to timestamp-based filenames. Here’s my ~/bin/prtface.sh:
DATE=$(date -Is) DIR=~/Pictures/PrtFace mkdir -p $DIR fswebcam -r 640x480 --jpeg 85 -S 10 --no-banner $DIR/$DATE.jpg eog $DIR/$DATE.jpg
Make sure to make the file executable:
chmod +w ~/bin/prtface.sh
Finally, re-map the Print Screen key. Open the Keyboard section in System Settings, and click the tab Shortcuts. Under Custom Shortcuts, add your new entry. (I found that
~ expansion was not supported for the command value, so use the full path to the script file)
Plans: Post to Twitter
I wanted to extend the script to post the picture on Twitter, given a user confirmation from a question dialog. I think Zenity would be a good match for the dialog. For the Twitter integration, I was looking at t, but didn’t succeed in configuring it correctly and I haven’t had the opportunity to tinker with it more. Hypothetically, the following (untested!) version of the script should do the trick.
DATE=$(date -Is) DIR=~/Pictures/PrtFace mkdir -p $DIR fswebcam -r 640x480 --jpeg 85 -S 10 --no-banner $DIR/$DATE.jpg eog $DIR/$DATE.jpg zenity --question --text="Do you want to show your silly face on Twitter?" if [ $? -eq 0 ] then t update -f $DIR/$DATE.jpg "Accidentally pressed PrtSc, which is re-mapped to take and post this photo of my clumsy face... http://arild.klavaro.se/data/re-map-obtrusive-prtsc-key-to-take-a-webcam-snapshot" fi