47: Custom LaunchBar search templates

Earlier this week, Stephen Hackett revealed how he finds all those animated GIFs so quickly: with an Alfred workflow that searches Giphy.

The workflow itself is a shell script which takes input, does some text replacement, and opens a URL. It's just two lines, but as a longtime LaunchBar user it seemed…complicated.

If I need to automate a repeated searching task, I set up a custom search template in LaunchBar. All that's necessary is to run a search on the site in question and replace the part of the URL corresponding to your search terms with an asterisk. Cribbing from Stephen's script, the search terms come after giphy.com/tags/. The script also does some preprocessing, taking out spaces in the search terms and replacing them with hyphens. I thought this might make it impossible to create a corresponding LaunchBar template — what if Giphy really chokes on spaces in URLs? I headed over to Chrome and manually typed in a test URL. The browser handled percent-encoding the spaces and Giphy automagically converted them to hyphens! It also redirected the base of the URL from giphy.com/tags/ to giphy.com/search, adding a little time to the page load — I adjusted my template accordingly.

One benefit of the slightly more complex Alfred workflow is that it specifies a keyword. Stephen set it to 'gif', sensibly enough. But I named my LaunchBar search template 'Giphy'. Since LaunchBar finds items by letters in their names, typing G-I-F won't find it! There are two possible solutions. I could put 'gif' in the title — something like "Giphy gif search" — but that's inelegant. The other option is to assign a custom abbreviation. This is done from the main LaunchBar interface, not the index setup window. I typed 'giphy' to find my new template and then did the one thing I never think to do in LaunchBar: reach for the mouse. Clicking on the name brings up a contextual menu where I can assign the logical abbreviation.

In the end, the setup in LaunchBar, Alfred, or any other launcher app is about the same complexity; it's a matter of choosing the one that works the best for you. There are subtle differences: Alfred interprets the input "gif [search terms]" at once, while LaunchBar changes from search to text entry mode after hitting space. Alfred's documentation gives "maps" as an example: you can choose Apple or Google Maps after typing your search terms. Perhaps if you're a true GIF connoisseur you need multiple search engines at your fingertips. All it takes is a little setup in the appropriate Mac utility.