lucky.rb
I really like making custom Services in Snow Leopard, and I’ve been looking for excuses to practice working with Ruby, so I created lucky.rb. When combined with Automator + Services, I can highlight text anywhere in OS X and press a keyboard shortcut to query Google with that text and replace it with a link to the top hit. This can come in handy when writing blog posts, commenting, chatting on IRC, etc.
Note that to use this you’ll need a Google API key. For more about setting up the script itself, check out its Github page. To make it a Service in Snow Leopard, open Automator and select “Service” from the startup screen. Then set up something similar to what you see below.
Automator notes:
- Keep in mind you’ll probably have to change the path to lucky.rb.
- You can replace “markdown” with “html” or “url” if you would prefer an HTML link or just the URL. If you want the URL you can even remove the -f argument completely as that is the default.
lucky.rb notes:
- There is very little error output, since the primary use of this is as a Service and as far as I can tell Automator hides all of the error output.
- I’m a total Ruby beginner, so pardon if my code offends those of you who have been writing it for a while. I’m sure it reeks of C++/Perl conventions and I would welcome feedback on how to make it cleaner.