Snapflickr update

I’ve been having trouble recently with the screenshots I take for these blog posts. I use snapflickr, a little script I wrote last year1 that takes a snapshot of a window or area of the screen and uploads it to my Flickr account. What I’ve been finding is that often the window I take a snapshot of looks like its inactive, even though its the frontmost window on my screen. I think the changes I just made will eliminate that problem.

I find snapflickr incredibly useful. It works very much like the builtin ⇧⌘4 shortcut except:

  1. It allows you to set the name of the image file.
  2. It starts out in window capture mode instead of rectangle capture mode. (As with ⇧⌘4, you can switch from one to the other by pressing the spacebar.)
  3. It (optionally) uploads the image to Flickr with a description.
  4. If the image was saved to Flickr, it opens the uploaded image’s page in my web browser.

I have snapflickr set to run when I press ⌃⌥⌘4 (I use FastScripts to set the keyboard shortcut and launch the script), which is easy to remember and easy to press. With the Flickr page for the image showing in my browser, I can use one of my TextExpander snippets for getting Flickr URLs to insert the image’s address into the post I’m writing. It works very smoothly.

The one fly in the ointment was that sometimes the frontmost window, the one I wanted to take a snapshot of, wouldn’t look like a frontmost window. The titlebar buttons would be gray instead of colored and selected text would be highlighted in gray instead of blue. This happened because snapflickr’s first action was to put up this window to get the filename and description information.

snapflickr window

After I clicked the Snap button, the window would go away and the cursor would change to a camera, ready to take the snapshot. It was this order of operations that sometimes caused the problem.

Because it appeared before the snapshot was taken, the snapflickr window would become active, putting the window I was going to take the screenshot of in the background. Occasionally—I never could predict when—the previously active window wouldn’t return to the active state when the snapflickr window disappeared.

The fix was pretty simple. I rearranged snapflickr to take the snapshot first, then bring up the window to set the name and description of the image file. So now when I press ⌃⌥⌘4, the first thing I see is the cursor change to a camera. It’s only after I take the screenshot that the snapflickr window appears, so the window I want to take a screenshot of never becomes inactive.

Apart from the rearrangement of a few lines, I had to make two changes:

  1. The screenshot needed a temporary name. Because the screenshot is taken before I’ve named it, I call it “temp.jpg” initially, then rename it after the info is entered.2
  2. The name of button needed to be changed from Snap since the snapping was already done before the button appeared. I decided to call it Rename, a choice I’m not thrilled with, but it’ll do until I think of something better.

New snapflickr window

The snapflickr code, along with a few other Flickr scripts, is in this GitHub repository. It requires Carsten Blüm’s Pashua application and Sybren Stüvel’s FlickrAPI library.

Update 2/21/12
Acting on suggestions in the comments and my own idea for further automating my workflow, I’ve made some more improvements to snapflickr. The most important improvement is that it now puts on the clipboard an <img> tag corresponding to one of the standard Flickr sizes for the uploaded snapshot. The size is chosen from a new set of options in the snapflickr window.

Snapflickr with background

The snapshot above, for example, will have an <img> tag of

<img class="ss"
alt="Snapflickr with background" title="Snapflickr with background" />

but without the linebreaks. By putting this tag on the clipboard, I save at least one step when I want to include a screenshot in a post.

Other improvements include deleting the temporary file if the user cancels at the dialog window and exiting the entire script if the user cancels during the screen capture.

I confess the new snapflickr window’s aesthetics leave a lot to be desired, but Pashua isn’t especially flexible when it comes to layout.

  1. And which is a descendent of snapftp, a script I wrote years ago—first in Perl and then in Python—that did the same thing except it uploaded the screenshot to an FTP server. 

  2. I suppose I could give it a unique name, but I don’t see much point in that. If the renaming fails and I end up with an orphaned “temp.jpg” file on my Desktop, I’ll probably just throw it away. I certainly don’t care if it gets overwritten the next time I run snapflickr

4 Responses to “Snapflickr update”

  1. Kurt Schwehr says:

    Thanks… you caused me to go out to the web, find ImageSnap, rip out XCode, clean up the formatting and throw it up on github as I’ve only wanted something like this for many many years. Now I just need to finish the cleanup and package it in fink.

  2. James says:

    I have two ideas, save temp.jpg file in /tmp and retitle the button to “Keep”.

    Also isn’t png a better format for screenshots?

  3. Dr. Drang says:

    I used to use PNG for my screenshots, James, but Flickr handles JPEGs better. When resizing, Flickr converts PNGs with transparency (the shadow around a window) into JPEGs with solid backgrounds. It works better to start with JPEGs in the first place.

    Keep does sound better as a button name. It implies that Canceling will not keep the screenshot, so I’ll have to add code to delete the temporary file—something I should do anyway.

  4. James says:

    Maybe even “Save”?