An Automator Folder Action for Screenshots and Dropbox

I strive for minimalism when using computers. Less software, less processes, less distraction. I have a block colour as my desktop background. I don’t install superfluous software, no matter how beautifully-crafted. My computer is a tool (well, my OSX partition is anyway), not a game, so I treat it as such. If you rely on your computer, treat it well. Know where everything is and know what’s installed at all times. If something becomes surplus to requirements, remove it.

I use Dropbox as my cloud sharing weapon of choice. I share folders with friends and colleagues, and all of my screenshots are saved to a sub-folder of my public folder so that I can easily share them with anyone. This workflow might seem inherently insecure, but I don’t tend to screenshot things that are particularly secret; whether that’s a result of my screenshots having been public for so long, I don’t know.

You can easily change your screenshots directory from your Desktop to your Dropbox folder by opening a Terminal (/Applications/Utilities/Terminal.app) and running the following command:

defaults write com.apple.screencapture location /Path/to/Dropbox/Public/Screenshots

I like to have them in their own folder as I use Public for other things and don’t want it becoming overrun with screenshots. I don’t delete images; occupational hazard.

You can now close your Terminal window and go back to ignoring it if it scares you. I know a lot of people are uncomfortable with it. Once you’re saving screenshots to that directory, you can download the Automator Workflow. Unzip and open with Automator. You’ll be asked if you want to install it. If you trust me, click install and the workflow is copied to the correct directory and opened for you to edit (you’re going to need to edit).

You should be presented with a screen that looks a little something like this:

Automator Screenshot

We’re only interested in the first box, where you’ve got some config to edit.

dropbox: The path to your Dropbox folder.
screenshots: The path to your Screenshots folder. Must be relative to $dropbox.
dropboxuid: Your Dropbox User ID. Go into your Dropbox Public folder, context-click (right click, thanks Apple) > Dropbox > Copy Public Link. Your User ID is the big number in the URL copied.
bitlyuser: Your bit.ly username.
bitlyapikey: Your bit.ly API Key can be found at the bottom of this page.

You may not care if your URL gets shortened. If this is the case; find the following block of code in the first box:

short=`curl -m 4 -0 "http://api.bit.ly/v3/shorten?login=$bitlyuser&apiKey=$bitlykey&format=txt&uri=$encoded"`
if [ -z $short ]
then
    short=$url
fi
echo $short

And replace it with:

echo $url

Now you’ll just get the Dropbox Public URL copied to your clipboard; not bit.ly (which bit.ly will probably prefer if you take a lot of screenshots!)

I’m making the following assumptions about your system:

  • You have Growl.app installed. If you’re not sure, open System Preferences and look for a pane under “Other” called “Growl”.
  • You have Dropbox installed
  • You have changed your Screenshots path (using the method above) to be within your Dropbox Public folder
  • You have OSX Lion installed. I don’t see why it shouldn’t work on Snow Leopard, but I haven’t tried and I can’t.

If you satisfy those criteria, you should have success with this workflow. It is, however, offered with no support and I will accept no responsibility if you break your computer playing around in the Terminal because it looks like The Matrix or trying to update Ruby (system Ruby works fine) or something. If you’re friendly and would like some help, please ask on my Formspring and I’ll try to help. I’m by no means an expert at Automator, bash or zsh scripting or AppleScript but I can get things to work. I suck at AppleScript so badly that I had to paraphrase the AppleScript portion of this Workflow from here.

Yes, Perkins, I’ve heard of Cloud.app.

bit tumblr-y, but a quote

Non-developers often assume an application is invariably more valuable with a feature than without it

Via literate programmer

I can really empathise with this sentiment. There’s a huge temptation instilled somehow in people buying websites that more features = better quality. We really try to get clients to spend money on quality marketing at Buffalo, but they rarely realise that a bucket of features is pretty irrelevant if people don’t know your site exists. In the above, you can substitute the word “site” and its variants above with anything really.

I must write out 1000 times…

Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions
Copying directories resets permissions

Not 1000, but you get the idea. Fuck.

impress yourself

Just recently, I realised how important impressing yourself is when trying to maintain enthusiasm with your job. Doesn’t really matter what you do (as long as you care!), but things can go stale if you keep doing the same thing over and over, and never really provoking an “AWESOME! I did that!” reaction. Even if it’s only something small (at 8 hours a day, 5 days a week, little things can be fairly impressive!), it can give you a needed boost to productivity (ugh), enthusiasm and general satisfaction with work, life and all that!

Personally, I get my kick from cleaning really crappy data. Lucky for me, I’ve had a lot of crappy data to clean recently, so I’ve been able to flex my XPath, Regex, semi-complex MySQL and image manipulation muscles relatively frequently. If you’re as much of a fanatical cleaner and hoarder as I am, cleaning data is probably for you. Grab a 50MB CSV and try to programmatically make sense of it. It’s fun! I promise.

Unit testing

This is something that’s been in my peripheral vision for some time now. I’ve periodically been struggling to see the need for unit testing in general, without any justification. I can obviously see the benefit of making sure that your code all works and, seeing as I frequently work on ecommerce sites, I can see it causing far fewer headaches when making changes to purchase processes – simply being able to run a script to see if anything I changed works right.

However, one drawback of unit testing as a concept is that computers are, as a rule, infallible when it comes to this sort of thing. Humans, on the other hand, are completely fallible. If I make a change to some code in my checkout process that has a knock-on effect I didn’t count on in my unit testing (like changing the way delivery is calculated/stored/whatever), I wouldn’t necessarily foresee there being any problems in the email that gets sent after a transaction is completed (that may seem pretty esoteric, but it happened today). Part of this issue arose because I didn’t write the original site, and there was no way for me to detect that this could’ve caused a problem without going through every file on the site and manually checking that there was a problem, but another part could have been solved if a good unit testing framework was in place.

Now, when I say “good”, what I really mean is “comprehensive”. Anyone can write a good unit testing framework and here’s how, in my opinion. You test /every single dependency/. Everything. Bar nothing. If unit testing could’ve solved my problem today, it would’ve been done a little something like this (not exactly like this because the code on this site is largely a mish-mash of procedural and I-don’t-quite-understand-OOP-so-I’ll-give-it-my-best-shot – I assume it would’ve been very difficult to express this as a unit test).

Say I have a method that outputs this email that gets sent. I would write a unit test to capture the output of that method (when supplied with sample data from my database table, for a little extra reliability). I would then take this method and write my own version of it inside my unit test, so that I know it’s correct and compare the output of the two methods. If they differ, I would (PHPUnit) assertSame(legacy_method_output,my_method_output), and the test would pass if I hadn’t fucked it up. Now, the perceptive among you will have spotted something wrong here. In order to write this unit test, I would first have had to know about this email’s pre-disposition to causing problems in the first place. This, in this case, is the entire battle. Furthermore, I would have had to completely rewrite the method, solely to test that the old method hadn’t been broken in some way. For future testing purposes, this is really useful but, chances are I’d just rewrite the method and move on.

All of this isn’t to say that unit testing is fundamentally flawed. Far from it, in fact. I can see that it’s an incredibly useful tool for documentation and future-updates. When I come back to code that already has a unit testing framework, I’d simply make my alterations, run my unit tests until they all pass, then write some more to cater for my currently augmented feature-set. I would then know (with only a shadow of a doubt) that everything is brilliant and nothing is going to get fucked up when I put my code live. That’s got to be worth it! Not only the above, but unit tests seem to me to serve as excellent developer documentation. If you want to know how something’s supposed to work, never mind asking the project manager or client (who probably don’t know, and don’t really care!), you can just look and the guy who wrote it will have told you! Brilliant.

The only (and sadly, this is a pretty substantial “only”) problem is time (as with everything, I guess). You get all of this great peace of mind, but you have to put time into it. And it’s not just a small amount of time either, it’s a lot of time. Once you’ve written all your code (maybe doing it as you go along – 30 minutes a day or something) you then have to write tests to try and break it, and cater for every potential outcome that could arise from user or developer input of the code you wrote. That’s a large investment of time. I can’t quite decide if the net gain is quite worth the input, but I’m tipping towards a yes. I spend a lot of time a bit stressed about whether a modification I’ve made is going to cause unexpected problems, and I’d really like to be able to be more confident with this. I’m also one of those people who likes doing little scripty things, and gets a great sense of satisfaction from ticking boxes and watching “make test” throw out 100% success. Maybe this is for me, after all!