Take me home

S3 upload Snow Leopard service

Written by August Lilleaas, published August 31, 2009

Snow Leopard, the latest addition to the OS X family, has a new and very powerful feature called services revamped the Services system, and made it a whole lot more useful. In short, services are contextual aware actions, and Apple has made it easy for users to create their own services with an updated Automator.

I wanted to familiarize myself with how the services system works, and create something useful. I created a service that lets you upload documents (images, mp3s, text documents, …) to an Amazon S3 bucket. Short summary:

  • Install
  • Right click image, choose “Upload to S3”
  • URL of uploaded image is pasted to your clipboard.

Awesome for sharing images on IM, email, irc, and so on.

Installing

  1. Download the service.
  2. Extract and copy to ~/Library/Services. Create the directory if it doesn’t exist.

That’s all there is. The next time you right click an image, there’ll be a “Upload to S3” option in the right click menu.

When you run the script for the first time, you will be prompted for your S3 login credentials. Don’t worry, they will be safely stored in your keychain, just like all your passwords are on OS X.

How it works

The service/Automator workflow uses a combination of Applescript and Ruby to get the job done. The applescripts handles the dialog boxes and fetches info from the keychain. The ruby script uses the aws/s3 gem to upload the file to S3. It installs the gem if it isn’t already installed. When the ruby script has uploaded the file, it will pass on the URL to a 2nd applescript which pastes the URL to the clipboard and provides feedback to the user.

The ability to execute ruby scripts out of the box from automator is new in Snow Leopard. So are the contextual services. Snow Leopard was released mere days ago, we can only begin to imagine the different ways people will make use of this new and powerful feature.

If you want to have a look at the source code, download the service (link above) and open it with Automator.

CHANGELOG

  • Sep 2. 2009: Checking if the bucket name is blank when the bucket name storage file exists.
  • Aug 31. 2009: Updated to use “documents” instead of “images”, to enable uploading of text files, audio files, and more.

Questions or comments?

Feel free to contact me on Twitter, @augustl, or e-mail me at august@augustl.com.