4

I use Cheese as my webcam software. I am trying to figure out a way to have it :

  • Start
  • Click a pic
  • Exit

when a script is executed. The script should not be asking for permissions and there shouldn't be any interruptions. So far,

#!/bin/bash 
cheese

I could only get it to do step 1. How do I do steps 2 and 3? The doc files don't mention an such option and I don't want to change the source code. (I don't mind camorama either)

  • I hadn't. I believed this SE is the only one which would have relevant questions. Anyways, the mplayer solution doesn't work for me. It outputs a blank (green) png. –  Jul 07 '12 at 06:58
  • http://askubuntu.com/questions/253189/can-i-make-the-webcam-take-a-picture-when-an-incorrect-password-is-entered Follow the link and you might get the answer you want. In the first three steps. after that you can write a crontab job. –  Jan 10 '16 at 06:31

1 Answers1

1

Voilá! Steps 2 & 3 follow:

This works, although it's awfully timing critical, tweak as you see fit, tried to comment it decently so you can see what's going on.

You'll need to install xdotool for this to work, as we're simulating keypresses to take the picture and exit (package 'xdotool')

Oh, and you'll need to turn off the 'countdown' feature in preferences, otherwise it'll likely CTRL-Q (quit) out of the program before it actually takes the shot.


#!/bin/bash
#
# L Nix <lornix@lornix.com>
# takeapic : take a photo with Cheese, using default settings, then exit
#
# start cheesing (2> because mine whines about cheesy stuff (ha!))
cheese 2>/dev/null &
# give WM some time to start up program (fails without this)
sleep 5
# set so we can determine if valid window(s) exist(s)
WINDOWIDS=""
# wait for up to 90 seconds (tweak this)
COUNTDOWN=90
while [ ${COUNTDOWN} -gt 0 ]; do
    WINDOWIDS=$(xdotool search --class "cheese" 2>/dev/null)
    if [ -n "${WINDOWIDS}" ]; then
        break
    fi
    sleep 1
    COUNTDOWN=$(( ${COUNTDOWN} - 1 ))
done
# did we get anything?
if [ -z "${WINDOWIDS}" ]; then
    echo "Cheese never started, something's wrong"
    exit 1
fi
# the shutter button is ALT-T
for WIDS in ${WINDOWIDS}; do
    # if you combine these like xdotool allows, it fails
    xdotool windowfocus ${WIDS} 2>/dev/null
    xdotool key alt+t 2>/dev/null
done
# pause a moment while taking photo
sleep 1
# now CTRL-Q out of the application
for WIDS in ${WINDOWIDS}; do
    xdotool windowfocus ${WIDS} 2>/dev/null
    xdotool key ctrl+q 2>/dev/null
done
#
lornix
  • 3,482