Sugar/Quick screenshot hack

From OLPC
Jump to: navigation, search

The Sugar keyboard shortcut alt + 1 on the XO captures the screen, and creates an entry in the journal that you can title and copy to a USB drive. The method is useful for a small number of screenshots, but does not scale.

This page describes a more advanced procedure to deal with multiple screenshots.

Background

Cynthia from the learning lab asked me (DanielDrake) to hack an XO so that taking a substantial number of screenshots and transferring them to her Mac is easy. Right now, it is tedious to copy screenshots one-by-one to a USB drive and then transport the USB drive to another system.

Requirements

  • An internet-connected XO running sugar
  • ssh access to a remote server on the internet, which we'll call remote.server.com (and your username is "user")
  • The internet-connected "target" computer

The decision was made to store the screenshots on a remote server and access them through the remote server to allow for the XO's IP changing, different XO's being used on different days, etc. It would also be realistic to store the screenshots on the XO and have the target computer access them over SSH, and that would only be a simple modification below.

Creating SSH key and configuring remote server

The XO needs to have passwordless access to the remote server. You need to create a ssh key pair. If you want to have multiple XOs set up like this, only one of them needs to create the key, then you can copy it to any more XOs that you want to use in this way.

  1. On the XO, launch a terminal activity
  2. Generate a SSH key:
    • ssh-keygen -t rsa
  3. Copy the public key to the remote server
    • ssh-copy-id -i .ssh/id_rsa.pub user@remote.server.com
  4. Log into the remote server (confirming that there is no prompt for password/passphrase) and create a screenshots directory
    • ssh user@remote.server.com
    • mkdir screenshots
  5. Logout of remote server
    • exit

Setting up the XO

  • At the terminal activity, create a local screenshots directory
    • mkdir screenshots
  • Create a script called at /home/olpc/cpscrn with the following contents:
#!/bin/bash
scp $1 user@remote.server.com:screenshots
  • Be sure to modify this line to reflect your remote server information
  • Mark it executable
    • chmod a+x /home/olpc/cpscrn

Modifying sugar

Sugar must be modified to save screenshots to disk, rather than to the journal, and then copy them over SSH. The modifications are in three parts:

  1. place screenshots in a special directory, with the correct file type (a changed file_path),
  2. run the cpscrn script to copy the screenshot over SSH (an os.system call),
  3. avoid adding the screenshot to the journal (a premature return).

How to modify Sugar:

  • Become root
    • sudo -s
  • For Sugar 0.84, open /usr/share/sugar/extensions/globalkey/screenshot.py in a text editor
    • nano /usr/share/sugar/extensions/globalkey/screenshot.py
    • Find the handle_key_press function,
    • ctrl + w handle_key_press
  • For Sugar 0.82, open /usr/share/sugar/shell/view/Shell.py in a text editor
    • nano /usr/share/sugar/shell/view/Shell.py
    • Find the take_screenshot function, about 85% of the way through the file
    • ctrl + w take_screenshot
  • On the line after the function declaration (def), change how the file_path is prepared, the red line is the new text that replaces the old text:
    def handle_key_press(self):
        file_path = os.path.join("/home/olpc/screenshots", '%i.png' % time.time())
        window = gtk.gdk.get_default_root_window()
  • About 10 or 11 lines below, after the call to screenshot.save, add two lines of code, the red lines are the lines that you need to add:
        screenshot.save(file_path, "png")
        os.system("/home/olpc/cpscrn %s" % file_path)
        return
        
        client = gconf.client_get_default()
  • Save the file and close the text editor

Accessing remote server

  • Configure your target computer to have access to the screenshots subdirectory on remote.server.com.
    • This is system-dependent.

Taking screenshots

  • Restart sugar so that your code changes take effect
    • ctrl + alt + erase (warning: will lose unsaved work!)
  • Press alt + 1 to take a screenshot
  • The journal will no longer contain the screenshot
  • The screenshot will be saved locally in /home/olpc/screenshots and also copied to the remote server
    • It may take a few seconds for the screenshot to be saved, compressed, and uploaded over the internet
  • You can then view the screenshot(s) on your target computer by opening the folder on the remote server

Notes

After update of build

After you update the build, the ssh key will have been removed, and you must re-generate it.

  • Generate a SSH key:
  1. ssh-keygen -t rsa
  2. ssh-copy-id -i .ssh/id_rsa.pub user@remote.server.com
  3. ssh user@remote.server.com
  4. mkdir screenshots
  5. exit

You will also need to reapply your changes to Shell.py or screenshot.py.