Eval Expression service for OS X

Eval Expression is a Mac OS X service to evaluate the selected text of any text field as a Ruby expression. My instinct was to choose Perl, however Ruby offers binary in addition to decimal, hex and octal numerical literals. The service becomes infinitely more useful if you assign it a global shortcut in Keyboard preferences. In my case I assigned a combination that seemed obvious, ⌘=

Keyboard preferences

It came about as I was working on some layout in Xcode 4 / Interface Builder, and needed to adjust the Y position of a view by a specific number of units. I’m lazy, and figured the computer should do the work, so I typed 768-35 and tabbed out. Unlike Acorn and Opacity, which evaluates the expression in numerical entries automatically, Xcode simply complained. Not happy, I created this service and it works like a charm. Some examples:

Download the Automator zip file from github, unzip and install to your ~/Library/Services folder.

A quick video of the service in action (note that I’m using my ⌘= shortcut to evaluate within Mars Edit):