Last One Out Turn Off the Music

With the holidays quickly behind us, you’ll likely start leaving your house again. Now, while some don’t like Sonos products for some reason, yours truly likes them tremendously, as voiced numerous times on this very blog.

If you’re anything like me, the first thing you do after you open your eyes is to throw a playlist or two onto your Sonos system, even before you start your morning routine. My playlists have a tendency of running long, though, and more often than not I find myself returning back home with the music still playing, because I was so busy remembering all the things I needed to take with me when I left that I didn’t remember to pause the music.

Given the current availability of location-aware automation tools, I thought it shouldn’t be too hard to find a solution for this that didn’t involve a daily reminder in iOS.

iOS Reminder

iOS Reminder

Turns out, Sonos refuses to cooperate with services like IFTTT, which would make this a breeze to implement. Bummer. (It also looks like the Sonos Controller for Mac isn’t AppleScriptable. A bummer as well.)

I did, however, find a Ruby implementation of what you could call a “Sonos API”, which is based on UPnP (Universal Plug and Play). With this little gem and a little spit and glue we can still make this work.

What we need

The solution comes down to three ingredients:

  1. The IFTTT iOS App to trigger the actual location change
  2. The aforementioned sonos gem to interface with the Sonos speakers
  3. A (powered on) Mac with Hazel, that watches a folder in Dropbox

Let me walk you through it.


The IFTTT App has a special channel called iOS Location, which can trigger either when you’re entering or leaving a certain location or area.

For the Action, we’re simply creating a file in Dropbox. By default, IFTTT will put this into the IFTTT/iOS Location folder. It’s up to you where you put it, simply remember the file’s location for the Hazel setup a few paragraphs down.

The contents of the file don’t matter, either, although we’ll look at a way to make use of the file contents in the bonus section below.

What is important is the filename. Quick tip: when you initially set up the rule in the iOS App, you have to go back in and edit it in order to be able to set the filename. I’m using sonos_pause in my example, as you can see below.

The IFTTT action

The IFTTT action

(Now, while I could share the ready-to-consume action directly over IFTTT with you, there’s little point in stopping your Sonos system when you’re leaving my house, I guess.)

Sonos Rubygem

Since the Sonos Controller for Mac doesn’t have an AppleScript dictionary, as mentioned above, we need to resort to other means in order to be able to control the Sonos speakers from afar.

To install the sonos Rubygem, execute the following commands in the Terminal:

$ sudo gem install sonos

(You may have to provide your user's password at this point.)

Sidenote: The latest released version of the Gem has an issue properly detecting stereo pairs and surround/subwoofer setups. I sent a pull-request to fix this. Until that is merged, you can download a patched version of the Gem if you have a stereo pair or a SUB in your environment.

Hazel Rules

In Hazel, add the IFTTT/iOS Location folder as a folder to apply rules to.

For the conditions, all we care about is the fact that the file needs to be called sonos_pause. When such a file is matched, we execute an embedded shell-script, which is quite simple indeed.

(The only reason for the source command is my rbenv environment. You can probably leave it out if you use the stock OS X Ruby setup.)

When the script is done, we move the file to the trash, so that the rule isn’t triggered over and over again.

The Hazel Action to pause Sonos playback

The Hazel Action to pause Sonos playback

And that’s it! Now, when you leave the geofence you set up in the IFTTT iOS app, a file will be created in you Dropbox, synced to your Mac, where it’s picked up by Hazel to execute the script to pause Sonos playback.

Easy, huh? (Yeah, I know.)

Bonus: Start playback when you get home

Of course, the pause action is easily reversed with a play action.

In IFTTT, set up another recipe to trigger when you enter an area, create a different file in Dropbox (I suggest sonos_play), and add a new Hazel rule to watch for that filename.

Starting to play in a multi-room Sonos setup could be unpredictable, though. For one, you wouldn’t want all rooms to play. And also, the volume could be set to a devastating value, as you could’ve been blasting Gary Clark Jr. before you left the house.

For those reasons, we’ll whip up a script that’s a little more sophisticated. It will purposefully set the volume to a value of 10 before starting playback. And it will take the name of the room to start playing in from the textfile.

Just make sure that you put the exact name of the room to play into your IFTTT Recipe.

The Hazel Action to play Sonos in a specific room

The Hazel Action to play Sonos in a specific room

Assuming you have a Sonos setup in the office, this could totally be used for an office prank. If you set up an corresponding Hazel rule, you could, for example, play the intro music to “The Office” when you get into the office. Then again, maybe not.

Future optimisation: Multiple users?

What if you have multiple rooms and multiple Sonos users, meaning that you don't want to pause while there's still somebody at home or at the office? I don’t have a ready-to-share solution for this scenario, but here’s an idea: If everyone is equipped with the IFTTT iOS App, you could track (using the “Append to file” action, maybe) who entered the geofence and only pause Sonos after the last one has left the house again.

Can you come up with any other creative uses for IFTTT with Sonos? Shoot me an email.

2013 – A Disappointment?

Originally spurred by Christopher Mims' essay for Quartz, John Gruber reviewed 2013 in the context of Apple and Technology at Large:

Was 2013 a seminal or particularly extraordinary year for technology? No, I’d say not. But it certainly wasn’t a “lost year”, by any measure.

He walks us through the rather incremental evolution in technology that came to market in 2013 that, when compared to the original products they incrementally improved upon, provide a rather stark revolution in just a few years. One of the most prominent examples would be the original iPhone released in 2007 compared to this year's iPhone 5S, which is, claims Apple, 40x faster than the original.

Gruber closes his piece with:

There’s a nihilistic streak in tech journalism that I just don’t see in other fields. Sports, movies, cars, wristwatches, cameras, food — writers who cover these fields tend to celebrate, to relish, the best their fields have to offer. Technology, on the other hand, seems to attract enthusiasts with no actual enthusiasm.

Wise words, indeed.

But, seriously, have any of those fields that are blessed with more enthusiastic writers seen any revolutions in 2013?

Let's find out.


While I'm not a fan of any sports that could be considered mainstream like soccer, baseball, or American football, none of these seem to have gained anything revolutionary in quite some time by my research. In soccer, FIFA announced the controversial roll-out of Goal-line technology to additional tournaments, but that's pretty much about it. And besides, does an improvement in rule-keeping really count as any kind of revolution?

A sport that is dearer to my own heart since 2013 would be CrossFit, which gained a lot of traction and popularity recently. But CrossFit, Inc., the company, has been around since the year 2000 and even the CrossFit Games have been held since 2007. So, they’ve been around a while as well.

Performance analysis and data-analytics seem to have picked up significantly in recent years, but it's debatable if this is an innovation to be attributed to sports, rather than, say, technology.


3D Movies have been pushed heavily for years now and 2013 was no different. But from an innovation-standpoint, nothing seems to have revolutionized movies. Theaters were dwarfed with Hobbits, the Hunger Games, and Thor, among others, this year, which are all splendid movies in and of itself, but they didn't particularly revolutionize.

If anything, the wide-spread availability of tools like GoPro cameras and even the iPhone 5S with its 120FPS slow-motion shooting capability has promise to open up movie making to more people than ever. But let's not get ahead of ourselves.


I've relentlessly watched Top Gear season 19 this year. I've been to the Frankfurt Motor Show in Frankfurt, too. Yes, there were more electric cars than I had assumed there would be. But Tesla has been shipping its Roadster since 2008. The other car news at the show revolved around everyone and his dog building Audi R8 look-a-likes, rendering calendar year 2013 as definitively a year of evolution on the car design and development front.

Google's driverless cars, which have been road-legal since 2012, have completed a proclaimed accident-free half million kilometers. It’s a great accomplishment, but it’s simply building on what they’ve already been doing.

Could Uber, who are disintermediating car-for-hire transactions everywhere, then be the innovation of the year 2013? Not really. The San Francisco-based startup had its inception in 2009 and rolled out a lot of its fleet in 2012 already.


No, Apple hasn't released anything to put on your wrist this year.

People are still buying watches like jewelry, with technology like the tourbillon in them that is more than two centuries old. Companies like Patek Philipe make a billion dollars of revenue a year by selling watches that cost $21,000 on average, putting them in the 8th spot of the biggest watch makers of the world with a marketshare of a stunning 3%. (That does sound familiar, doesn't it?)

And we'll just pretend Samsung's awkward Galaxy Gear ad has never happened.


My photography has severely suffered in 2013. But that wasn't due to the lack of newly available camera gear. The current crop of professional D-SLR bodies from Nikon and Canon are nothing short of outrageously well-built, photo-construction machines.

And take the new kids on the block, like Fuji's X Series of mirror-less cameras (I own an X-E1, released in late 2012) or Sony's new A7, a full-frame mirror-less camera body with interchangeable lenses, which is something that we hadn't seen in such a compact format before.

However, the real photography revolution of the century was the transformation from film to digital several years back. First with bulky D-SLR bodies, now with these incremental steps to achieve great image quality with a minimal amount of gear, accessible to as many consumers as possible.

Sure, comparing the images coming out of the A7 to the images of the first compact cameras in the early 2000s feels like a drag race between a Dacia Logan and a Mercedes SLS. But year-over-year, camera makers have taken very conservative, incremental steps on the pixel ladder, improving resolution and image quality.

As well, if you had a time-machine and showed the images (and movies) created by the camera in this year's iPhone 5S (a telephone, for crying out loud) to someone a mere 10 years ago, you'd be accused of witchcraft. (Again, it must be noted that most of the incremental imaging improvements in the iPhone 5S are in software, not the actual camera hardware.)


I am able to plot a bit of an uptake this year of more conscious and healthier food-intake in some of my immediate surroundings. This may in part be due to a partially proportional amount of uptake in food allergies or just due to my getting older.

Eating healthy isn't exactly a new thing, though. Quite the contrary, in fact. The fundamental rules of diets like Paleo are based on our primal past. And if you just want to grab your greens from the farmers market instead of eating at McDonald's (no offense) that's perfectly fine too.

On the tools-side, blender manufacturers like Vitamix must be one of the most conservative on the planet. Their model 5200 has been around since 2007, you can still by it new (I did), and you get a 7 year warranty on it. Why would you replace your blender every year anyway?

Side-note: If you are looking for a great, practical introduction to Paleo, get the Paleo Primer. It's much less theoretical than the usual suspect and full of great varieties that'll even make your kids happy.


That brings us to the technology sector. Has 2013 really been this disappointing?

For example, 3D printing got much more affordable in 2013. While it may still be a few years off until you can finally stop leaving the house altogether and print fresh underwear at home, you can get a 3D printer for under $1,000 these days. Commercial products like the Cubify Cube are a bit more expensive, but there's always the RepRap Open Source project that will even supply you with the accompanying printable objects.

And, these printers are being heavily used by the people who are prototyping the products you’re buying right now. Walk into many design studios and you’ll find bins full of 3D printed mock-ups and prototypes.

2013 has also been the year of the civil drone. Both Amazon and DHL have announced tests of commercial package delivery via unmanned drones, all of which were made possible by advancements in technology.

And even the controversial technology stepchild that is Google Glass deserves a spot in the technical innovations of 2013, even though Mims laughs at it in his piece. I wouldn't go so far to award it the Mobile Product of the Year, but it is an innovation, plain and simple. It might take another few years to really come to fruition, but it’s a definite sign of how the computer-to-perpetually-connected-personal-device-transition is going to play out.

In conclusion, most of the innovation in 2013 flew under the radar (some quite literally) and was mostly incremental and evolutionary. But when comparing several different sectors, it's glaringly obvious that we technologists have been spoiled by a continuum of tiny revolutions in a very short, compressed timespan. So much so, that we're caught up in declaring each individual product either revolutionary or not when in reality, innovation is happening steadily, right in front of our eyes, sometimes creating a new continuum that cannot be grasped immediately.

Repeating revolutions at the pace they just so happened to occur in the past is not only not feasible in the long run, it's a completely unrealistic and unhealthy expectation.

Take a step back, look at our connected world as it is today, and you'll realize that what we have here is the amazing result of hundreds of innovators putting their lifeblood into their products, some of which among our direct peers.

I'm excited about technology today and just as excited about what the future brings.

Moving to Middleman

As you may or may have noticed, some things have shifted around a tiny bit on these very pages: A while back, I quietly relaunched the site without much fanfare.

The visible changes are subtle, to say the least. The link colour is slightly different, the menu changes a little differently on smaller displays (or with a resized browser), code tags are highlighted a little differently, and that's largely it. Oh, and the usual RSS Feed hiccups of course.

However, I completely switched away from my own little Rails app hosted on Heroku to the Middleman static site generator and host the output on Amazon S3 and Cloudfront.

But, why?

Frankly, there were no pressing reasons. The site worked and used a lot of caching, so the effect of the kerfuffle concerning Heroku performance a while back was negligible.

Sometimes you just need change for change's sake. I like fiddling with technology and this blog has, in its 13 years of existence in one form or another, always been a technology testbed and playground for me.

This time is no different. I had a keen interest to play with static site generators and my own blog application wasn't special enough to keep it running just for sentimental reasons.

But, why Middleman?

Middleman is one choice out of many when it comes to static site generators.

In the Ruby world, apart from Middleman there's Jekyll, which powers, among others, GitHub Pages and recently went 1.0. Then there is Octopress, which is an add-on for the aforementioned Jekyll and offers some nice bootstrapping options.

In the Python world, people are talking first and foremost about Pelican. But there are also options like the pun-heavily named Hyde.

Middleman convinced me with a solid plugin architecture, not too many defaults that make it all obvious which tool you used to create your site, and a sensible approach to the "writing offline with previews" workflow. Some of the other contenders performed well in some of these areas but fell short in others. (I'm making no attempts to write a comprehensive comparison article for static site generators. This is what works for me.)

Additionally, Middleman supports compiling fancy new languages (or language extensions) such as Coffeescript and Sass out-of-the-box and without much fiddling. It just works.

Switching parts

To reduce complexity, I also switched from Compass and Susy to Twitter Bootstrap as the framework. (I've actually used the Sass-port of Twitter Bootstrap since I had no desire to switch to Less.) That means I had to port the grid and individual components over, which turned out to not be too hard.

My own implementation of footnotes was rendered obsolete by the use of the kramdown Ruby plugin that supports Multi-Markdown footnotes out of the box.

Likewise, my backend implementation to extract captions of img tags gave way to a very simple, jQuery-based implementation that grabs all the qualifying images on a page and generates the caption elements on the fly. It's not optimal, but could definitely be worse given the JavaScript execution speed of modern browsers.

Lastly, syntax highlighting is still handled via Pygments internally, but the interface to it is no longer my original implementation that is called after saving an article to the database (since there, well, is no database). Instead, I'm using Rack::Codehighlighter, which Middleman can easily cooperate with.

Middleman and Blogging

Middleman itself is setup pretty well for serving as a blog by way of the official blogging extension.

This extension gives you the usual suspects like a bunch of articles in reverse chronological order, tags, calendar pages, drafts, the whole nine yards. You could even run the blog integrated as a sub-directory into a regular corporate site with lots of static pages, not unlike Squarespace offers blogs as page types alongside its regular pages.

The workflow to write a new article (or create a new static page) is to simply create a file with a supported template extension (I use .markdown) within your source directory.

In order to keep my templates separate from the actual articles I moved the source directory for the articles to source/articles/ instead of the default option of putting them directly into source/:

Instead of creating the file manually, Middleman offers a handy shortcut that converts the article title to a permalink and also prepends the date:

$ middleman article "My new Article"
  create  source/articles/2013-02-25-my-new-article.html.markdown

With this file in place you can open it up in your favorite text editor and start typing. When you're ready for a preview, start middleman server and point your browser at http://localhost:4567. Assuming a typical blog homepage with articles displayed in reverse chronological order, your new article will show up at the top. Clicking the link will open the detailed article page such as /2013/02/25/my-new-article.html.

Since Middleman integrates with LiveReload, every time you save the file in your text editor, your browser will recklessly reload to show you the latest changes. Especially for more sensitively arranged articles with lots of images and/or code samples this is a godsend.

Speaking of drafting articles, Middleman supports a published: false attribute in its Frontmatter, which will exclude those articles from being included when you build the site.

Of course, I'm still starting out articles separate from this preview cycle in iA Writer or Byword on my Mac or iPad.

What's next?

I’m planning to publish additional articles covering blogging from an iPhone or iPad in conjunction with a static site generator in the weeks to come.

Also, there are a few tweaks I need to make to improve building the blog and publishing it to S3 in the least amount of time possible, which is a challenge I gladly accepted.

Semantic Tagging with Zemanta and Alfred

I’m struggling finding a satisfying taxonomy for tagging my posts here. There was even a time when I would enter them but hide from from display because of how unhappy I was with their ability to tie posts together or increasing discoverability for search engines.

That said, I was pretty intrigued when Brett recently blogged about his use of Zemanta to auto-tag posts on his Jekyll-based blog.

Since I’m not using Jekyll, however, I had to be a little more creative with adapting this workflow. I actually used it as an excuse to learn more about one of the headlining features in Alfred 2: Workflows.

Strictly speaking, Workflows in Alfred tie together triggers, inputs, actions, and outputs to automate common tasks. They operate on text, files, or even remote contents such as your GitHub repositories, like this incredible GitHub workflow does.

(Another handy list of workflows, which happen to be often buried in the bowels of the Alfred forums, comes from macminicolo, who blogged about Ten Alfred workflows for IT recently.)

As I despise PHP, I did not go down the route many others take when writing Alfred Workflows. I used Duane Johnson’s beginnings of an Alfred 2 Ruby Framework and implemented my Workflow based on that instead of using David Ferguson’s more sophisticated PHP class. Also, Dennis Paagman’s alfredo Rubygem was very helpful in generating the XML-based responses that the Alfred Workflows need to return to build up responses in the Alfred GUI.

Sadly, system Ruby on Mountain Lion is still 1.8 and the zemanta Rubygem Brett used to implement his auto-tagger is not compatible with Ruby 1.8. Fortunately, there is an alternative API implementation available: The term_extraction Rubygem by Alex Rabarts.

All keywords provided by the Zemanta Tagging Workflow

All keywords provided by the Zemanta Tagging Workflow

Armed with that gem and the Duane’s Ruby framework I started cobbling something together which works rather nicely. It will either take a complete folder of individual article files for you to pick from or, alternatively, take content you have previously put onto the clipboard and sends that to Zemanta for tagging.

The result of this operation is then put back onto the clipboard for you to paste into whatever editor you want.

It even has a built-in setup keyword zemapi to make providing the workflow with the necessary Zemanta API key a breeze.

The list of articles to select from when working directly with a folder

The list of articles to select from when working directly with a folder

Apart from giving the Workflow an API key to use, you should provide the zemfile keyword a Search Scope to just the folder containing your articles. To do that, open up the Workflow in Alfred Preferences, double-click the zemfile keyword and select your desired folder in the “Search Scope” tab in the slide down panel. I keep my articles in ~/Dropbox/Articles/, for example.

As Brett mentions in his article, the terms returned by Zemanta are sometimes a little verbose and need a little manual tidy up. They’re also not replacing my manual tags any time soon. But one thing I will start using them for is meta tags.

Download Workflow

(The source code for the workflow is also available on GitHub.)

Happy Easter!