Sugar/Quick screenshot hack
The keyboard shortcut alt + 1 on the XO captures the screen; this advanced procedure makes it easier 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 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.
- On the XO, launch a terminal activity
- Generate a SSH key:
- ssh-keygen -t rsa
- Copy the public key to the remote server
- ssh-copy-id -i .ssh/id_rsa.pub user@remote.server.com
- 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
- 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
- For Sugar 0.84, open /usr/share/sugar/extensions/globalkey/screenshot.py in a text editor
- nano /usr/share/sugar/extensions/globalkey/screenshot.py
- 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
- Change how the file_path is prepared, the bold line is the new text that replaces the old text:
def take_screenshot(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 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
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:
- ssh-keygen -t rsa
- ssh-copy-id -i .ssh/id_rsa.pub user@remote.server.com
- ssh user@remote.server.com
- mkdir screenshots
- exit