Creating a Better Print Screen, Part I
After reading Randall Degges excellent post How I learned to Program, I decided to give creating a screenshot program a try. It’s always a bit of work to take a screenshot, upload it to the web and then grab its permanent link. So being a geek, I thought it high time this process was automated!
I tried writing the program in python only, so that there were fewer dependencies, but using the commandline program scrot as the screenshot snapping program added a lot of flexibility to the options for the screenshot.
Without further ado, here are the parts of the program.
Take Screenshot with scrot
I start with a bash script that calls scrot, and passes in my program as a parameter to scrot.
Next, chmod +x the bash script:
Scrot Options explained
- -d 5: Delays the snap for 5 seconds.
- -u: Use the currently focused window.
- -e ‘script’: Execute the following script after the screenshot is snapped.
- $f: passes in filename to script.
On to the Python Picture Uploading Program
Scrot takes a screenshot after a delay of 5 seconds of the currently active window, it names the file with the current date-screenshot.png, it then passes the filename into my program, “screen-upload.py”.
Upload Image to Picasaweb
For uploading the image to Picasaweb, I used the gdata module. Installing it involved the standard: Download the module, extract it and cd into the directory and run “sudo python setup.py install”.
In version 2 of screen-upload, I will rewrite the authentication to use Oauth2, so that the authentication is more secure, for the alpha version, I am just passing in the users email and password into the gd_client object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Copy URL into the Clipboard
Copying the URL to the clipboard is easy as long as you are not too concerned with cross-platform compatibility. I used the gtk module to gain access to the clipboard on Linux systems.
1 2 3 4 5 6
This can be made more cross-platform with a series of try statements that load platform specific libraries.
1 2 3 4 5 6
Setting up the Keyboard Shortcut in Gnome 3.
I had a bit of a bother creating a keyboard shortcut in Gnome. I created a new shortcut in the keyboard settings configuration, but nothing happened.
Long story short: I created a shortcut under “Custom Shortcuts”. I called it “Take Screenshot” and I named the script “screen-upload”. Then I created a symbolic link to the script in /usr/local/bin.
This did the trick, now when I press the PrtSc button, a screenshot is taken of the current window, and its uploaded to Picasa and the URL of the image is copied in to my clipboard!