Sugar/Quick screenshot hack

From OLPC
< Sugar
Revision as of 14:31, 28 July 2008 by Bjordan (talk | contribs) (Setting up the XO)
Jump to: navigation, search

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 stick and then transport the USB stick 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.

  • Become root
    • sudo -s
  • 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
  • Modify the top of the function so that it looks as follows:
    • The bold line is the line that you need to change
    def take_screenshot(self):
        file_path = os.path.join("/home/olpc/screenshots", '%i.png' % time.time())
        window = gtk.gdk.get_default_root_window()
  • Approximately 10 lines below, add two lines of code
    • The bold lines are the lines that you need to add
        screenshot.save(file_path, "png")
        os.system("/home/olpc/cpscrn %s" % file_path)
        return
        try:
  • 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 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