Show IH: Search StackOverflow from Keyboard Shortcut

This week, I asked folks on IndieHackers: “what do you google on a regular basis?” (I’d love to hear your thoughts on the thread.)

The top comment came from @grammakov:

StackOverflow solutions. Story of my life. I’m constantly googling for answers to error messages, and the text of the error message is usually available on Stack Overflow.

I figured I could hack together a keyboard shortcut to select an error message and search StackOverflow.

Demo

Here’s how to do it yourself:

Part 1: Create the Automator Service

1. Open Automator.

2. Create a new workflow and pick “Service”

3. Search for “Run Applescript” and add it to the document:

4. Paste the following code as the Applescript:

on run {input, parameters}

set search to input as text

do shell script "open 'https://stackoverflow.com/search?q='" & quoted form of search

end run

(caveat: I’m an epic n00b at applescript…code feedback is welcome.)

It should look something like this:

5. Save it somewhere on your computer, such in a “utility” folder. I called my service “searchStackOverflow”.

At this point, you should be able to select some text, right click and see searchStackOverflow in your “Services” list.

Part 2: Create the keyboard shortcut

Once the service is up and running, creating the keyboard shortcut is a piece of cake.

  1. Inside of mac System Preferences, go to Keyboard Shortcuts Services.
  2. Scroll to searchStackOverflow and choose a keyboard shortcut. I chose COMMAND+OPTION+SHIFT+O.

And voila! You should be able to select any piece of text on your machine, press the keyboard shortcut, and see results straight from StackOverflow.

Hope this is helpful!