Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Taking pictures with your Linux Laptop every time the lid opens
1 point by interesse on Jan 14, 2011 | hide | past | favorite
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:

  #!/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`;
    }
  }
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.

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?



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: