February 20, 2012 at 9:08 PM by Dr. Drang
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.
snapflickr incredibly useful. It works very much like the builtin ⇧⌘4 shortcut except:
- It allows you to set the name of the image file.
- 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.)
- It (optionally) uploads the image to Flickr with a description.
- If the image was saved to Flickr, it opens the uploaded image’s page in my web browser.
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.
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:
- 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
- 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.
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
The snapshot above, for example, will have an
<img> tag of
<img class="ss" src="http://farm8.staticflickr.com/7052/6773457324_5b2cbdca97_z.jpg" 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.
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