Automatically SCP Screenshots from the XO up to the XS

After fooling around with sshfs and incron and whatnot with the Journal in an attempt to get screenshots on my XS (not to mention dealing with the peanut gallery on my chat server), I was at the end of my patience.  If you’ve ever delved into the Journal file structure, you know it’s tricky business.  So I started XChat, logged into the olpc-devel IRC channel, and asked if there was an update to the Quick Screenshot Hack.  Lo and behold, one of the devs, Quozl, got me all fixed up.
Here’s how I got this to work…

First, on the target XO, create your screenshot directory:
mkdir /home/olpc/screenshots
For scp to work, you’ll need passwordless ssh access.  Here are some easy instructions for the server and the client.
Make sure to successfully ssh into the XS.  Seriously, ssh in from the XO and make sure you can get to the XS without a password.  The first ssh session lets you accept the XS so the script below will work.

[Note – having an olpc user on the XS can sometimes keep stuff sorted out rather than dumping this into some else’s dir]
I made a script on the XO called /home/olpc/cpscrn (copy screen) with these little arguments.  Oh, I have an XS with an Apache server, which is handy.  The first command scp’s up the screenshot.  The second command copies the screenshot file on the XS with a timestamp for archive purposes.  You’ll see later why I’m doing this.
#!/bin/bash
scp -P port $1 olpc@schoolserver:/var/www/html/olpc/screenshot.png
ssh -p port olpc@schoolserver ‘cp var/www/html/olpc/screenshot.png /var/www/html/olpc/$(date +%Y-%m-%d_%H%M%S)-screenshot.png’
Of course chmod +x /home/olpc/cpscrn
Here’s where Quozl got me fixed up.  I didn’t know where the path to this darn file was, despite grepping all the live long day.  That should probably be a country song.  “Grepping all the live long day.”  Anyway…
Simply edit this file (now that you know where it is):
/usr/share/sugar/extensions/globalkey/screenshot.py
Look for handle_key_press and add the second line as you see here.  If you don’t want to keep your screenshots in /home/olpc/screenshots, modify that accordingly.

    def handle_key_press(self):
        file_path = os.path.join(“/home/olpc/screenshots”, ‘%i.png’ % time.time())
        window = gtk.gdk.get_default_root_window()
Even if you’re not going to run a script when you take a screenshot, you still need to add the return line.  Otherwise your screenshots will disappear into the ether (I found that out the hard way).  The second line isn’t mandatory, it’s just what you want to run when alt+1 is pressed.  You could play a sound file for all I care.  Or just omit it.
    screenshot.save(file_path, “png”)
        os.system(“/home/olpc/cpscrn %s” % file_path)
        return
Save and exit and restart Sugar.  Make sure the remote directories exist and have the proper permissions.  When Sugar comes back up, hit alt+1.  In about 10-15 seconds (or at least on my LAN) you’ll see screenshot.png come up on the remote server.
You’re probably wondering, “Why in the heck is she copying the screenshot.png file after it’s up?”  Well, lemme show you.
In /var/www/html/olpc I have this simple index.html
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
<html><head>
<meta content=”text/html; charset=ISO-8859-1″ http-equiv=”content-type”>
<title>XO Screenshot</title>  
</head><body>
<br>
<img src=”screenshot.png” height=”700″ align=”center”>
<br>
<a href=”../index.html”>Home</a>
</body></html>
Guess what that does?  Oh, it displays the current screenshot when you go to http://schoolserver/olpc
I’ve also got a record of all the screenshots I took sitting right there in /var/www/html/olpc
-rw-rw-r– 1 olpc olpc 49K 2011-01-07 19:37 2011-01-07_193711-screenshot.png
-rw-rw-r– 1 olpc olpc 49K 2011-01-07 19:42 2011-01-07_194214-screenshot.png
-rw-rw-r– 1 olpc olpc 347 2011-01-07 03:06 index.html
-rw-rw-r– 1 olpc olpc 49K 2011-01-07 19:42 screenshot.png

See how screenshot.png and the latest dated .png have the same timestamps?  They’re the same file.  This way you can have only a few second delay for “live” presentations without a projector, as XOs can easily view these screenshots in the Browse Activity.  All you need is a LAN and all the users need to do is refresh their browser when there’s a new screenshot.  Of course screenshot.png is overwritten everytime you hit alt+1 on the XO, but that’s OK as there’s a “permanent record.”
Later you can go back into /var/www/html/olpc and get all the screenshots for any documentation you need to do up. 
Don’t forget to clean out /home/olpc/screenshots on the little XO when you’re satisfied you’ve gotten everything.

If you don’t have an XS and want to host a presentation with the XO you’re taking the screenshots from, all the extra hardware you’ll need is a USB ethernet dongle, an ethernet cable, and an AP.  Use dnsmasq for DHCP and boa for the webserver so the XO can make its own little “LAN.”  Both dnsmasq and boa are really light.  And there’s the added bonus of not having to scp anything, as you can simply use cpscrn to put the screenshots in a directory served by boa.

Resources:
And many thanks to Quozl

Leave a Reply