Skip to content

Search sites from anywhere via abbreviations

Note: This post is no longer updated. Please see the version 2.0 post for current details and download links. This post remains because it has a fair bit of information about the macro in general.

Nearly five years ago, I wrote about my simple Keyboard Maestro web search macro that let me search many web sites from anywhere within macOS. While it worked well, it felt a bit cumbersome—I had to scan a pop-up palette of sites, and then press the proper key to select the site I wanted to search (so I had to keep the list relatively short). Then I'd wait for a new prompt to appear, type the search terms, and press Return.

Because of my macro's convoluted interface, I found myself using our own Butler most of the time, as it offers an interface similar to SafariKeywordSearch (which works in Safari as an extension; I was reminded of it due to a recent post by @danmoren on Six Colors). Both it and Butler do keyword searches, so you can type d best home vacuums to search DuckDuckGo for best home vacuums, or gm Tokyo to search Google Maps for Tokyo.

I decided to rewrite my macro to work like those apps do, but with an added feature: I use a number of browsers, and there are times I want my search to run in something other than the default browser. Using my rewritten macro, I can now optionally specify a browser in which to run the search. So when I activate the macro, I can use one of two different formats for the search command:

Both of those searches will search the Apple Movie Store for movies with the keyword disaster; the one on the left will use my default browser (currently Safari); the one on the right will use Edge.

The macro includes a number of predefined searches, inclcuding many for Apple's various stores. The list can be customized with relative ease, and there's an easily-accessible help window that lists all your shortcuts (though you have to manually keep that up to date when you add new ones).

Install and use the macro

Step one, download the macro and import it to Keyboard Maestro. The macro will be disabled by default; activate it, and you may want to change the shortcut from what I've chosen, which is ⌃⌘W.

If you wish, jump to the release notes section to see what's new in v1.2—it's pretty big news that will make keeping up with future releases much easier!

It's ready to use out of the box; I suggest typing help the first time you use it to see the list of predefined shortcuts. If you'd prefer, click the small image at right to see the current list, as shown in the macro's help.

To use, press the assigned shortcut key, then type the desired site abbreviation, the optional browser, and the search terms, each separated by a space from the others.

Modifying and updating the macro

Rather than explain here how to modify and update the macro, you'll find that information in the first comment in the macro itself. It will be easier to keep that information current than to try to make changes here any time something changes going forward.

Removing existing entries is trivially easy. Adding new shortcuts and searches is quite simple. Adding or removing browsers is just a bit more complicated, but still pretty easy. All of those things are (hopefully well) explained in the comment within the macro.

How it works

I'm not going to go through this step-by-step, but here are the basics on how this macro works.

  1. A defined set of shortcuts and sites is stored in a variable. Users can add their own shortcuts and sites in a separate step; they will be added to the stored variable. The format uses a bullet (•) as a separator between the shortcut and the search site, as well as to identify the section(s) of the URL that contain the search term (i.e. •SEARCH•). I chose a bullet because that character isn't valid in URLs, so there shouldn't ever be a match in a search string.
  2. If the user types help, the help text is displayed, along with a dialog explaining how to restart the search process; assuming the user goes forward, the macro is restarted and the currently-running macro is canceled.
  3. If the user didn't type help, the macro makes sure they typed at least two "words," where the first word is the shortcut, and the second word is at least one word for the search term. This step (and the help check) are in a while loop, so the input dialog will show up again and again, until the user either types help or uses the proper search format.
  4. A regular expression search splits the user's input into two separate variables, one for the shortcut and one for the search term. The search term is then filtered for use in a URL (i.e. spaces become %20, etc.).
  5. The stored list of shortcuts is checked for a match; if one is found, the URL is retrieved, the •SEARCH• placeholder is replaced with the URL-safe search terms, and a flag is set to indicate a match was found. (I don't do this when checking to make sure the user has entered two words because it requires parsing the full list of search sites, and that would have to be done each time through the loop.)
  6. If the "match found" flag is set, the search is sent to the default browser. If the "match found" flag isn't set, the macro displays an error notification and ends.

The only really tricky bit (for me) was figuring out the best way to relaunch the macro after opening the help window. I'm still not thrilled with how it works now—the window will stay open forever unless the user closes it—but it's passable enough for regular use.

If you have any questions, or would like to see a favorite search added to the defaults, please feel free to ask, either here as comments or via email.


Release Notes

Dec 22 2021 — v1.2 Big news in today's update: The macro now includes an update checker and download tool! No longer do you have to return to the blog, or hope you catch an announcement on Twitter to find out I've updated the macro. I've spent my free time over the last couple of days designing a simple, highly-private (no data sent to my server), and easy-to-use update check subroutine that I can use in all of my macros.

I'll be posting about it in detail soon—including a sample project that can be easily modified for use with your own macros—but for now, here's a sneak-peek screenshot of how it looks in action on the sample project (click to see the full image):

It works by checking the version number of the installed macro against the latest version number, as downloaded from my server. If there's a newer version, you can choose to download it, do nothing at the time, or opt out of future checks. (You can also simply disable the subroutine that runs the update check; it won't affect the macro's operation at all.)

It does require one permanent variable in Keyboard Maestro to track when you last checked for an update. The variable is named zzzRGwebsearch_lastchecked to make it easy to find in the list—if you delete it, you can force the macro to check for an update right away. (If you disable update checks entirely, of course, you can just delete it and it should stay gone.)

This has been on my "someday I should..." list for a long time, and I'm quite happy with the way it came out. I'll be interested in hearing how well it works for everyone—though note, you won't be able to test it until version 1.3 comes out, because, well, you don't have an update checker in your version of the macro yet! I have some ideas for 1.3 already, so it'll probably release over the weekend, and you'll be able to test the updater then.

As for other stuff in 1.2, there's a new search shortcut (MIT) for Macintouch, Macworld's search (M) now runs on their site instead of through DuckDuckGo, and I added a "how many shortcuts" counter to the search dialog box, just for fun. Download via the link above, update, and you'll hopefully then be automatically notified about v1.3 when it releases.

Dec 21 2021 — v1.1 Key changes in this version:

  • Added sixcolors and youtube to the list of shortcuts.
  • Added a new optional subroutine to check for duplicate shortcuts (see below for more)
  • Other changes detailed in the release notes within the macro

The biggest change in this version is the new duplicate check subroutine. This routine makes sure you haven't assigned two sites to the same shortcut. Nothing bad happens if you do, other than the macro will only ever use the last of the duplicate shortcuts.

The subroutine will notify you of a duplicate shortcut and end the macro; you can then find and remove the dupe. The subroutine is fast—it takes about a tenth of a second—but that's still notably slower than just putting the search dialog onscreen (about a hundredth of a second), so I've left it off by default. You can enable the subroutine by enabling the second step in the macro (highlighted in green); I'd recommend leaving it off, though, unless you try a shortcut and find it's opening a site you didn't expect.

Because there are now two files in the macro, they're stored together in a new macro group. This doesn't really change the updating instructions, though, other than you'll have to enable the macro group and not a single macro.

Dec 20 2021 — v1.0 Initial release.

21 thoughts on “Search sites from anywhere via abbreviations”

    1. Argh ... helps if I enter a full URL instead of just a filename. Fixed now—thanks!


  1. Link for macro isn't working. Looks great. I think this will replace my very limited macro for this. Thanks for posting. Greg

  2. Must have been updated as I was writing. But I see a bunch of pieces. Not sure I know how to enable.

    1. A bunch of pieces? It should be one macro—I just downloaded it from the post, and that's what I got. What are you seeing?


  3. 01)a Search Mac OS X Hints
    02)b Search Macworld
    11)h Bing
    12)i - Maps
    13)j - Images
    21)p Google
    22)q - Maps
    23)r - Images
    41)w Wikipedia
    42)x Wolfram Alpha
    44)y Edmunds New Cars
    They are highlighted when I go to KM after double-clicking the download
    And now I can see it's a "Pop Up - Web Search" Group
    And Control-Command -W doesn't show up in the list of shortcuts

  4. Maybe I accidentally got the old ones—web_search_palette. I redownloaded, so think it's good.

    Thank you.

    1. You may have clicked the link in the first paragraph, which would have opened the original article, and in there is a download link for that older version—because that's exactly what you did get.

      Glad it's all sorted now—just delete that other one.


      1. Took me a while to figure out that it's called "___Global - Hot Key." And then I ran into issues with hotkeys in other apps. Need to find the method to reveal all the shortcuts

        Great macro.

        AM-Apple Maps.

        APH takes to Apple Music? Doesn't matter. I was just expecting iPhone Apps.

        Amazon- maybe Z for shortcut

        Just saw that DuckDuckGo announced plans for a browser

        PS: If you want to delete all my post, that's fine. They don't add much now

        1. Greg:

          Now I'm confused; it's *not* called "___Global - Hot Key" ... I don't even think the old one was called that. APH is Apple iPhone Apps—you can't go by the URL, because Apple still calls stuff iTunes in many places. Try it, you'll see.

          But you can also change any shortcut you want—just replace what's there (and do so in the help text as well, in case you forget). That's all you'd need to change; it would then "just work" with the new one.


            1. I don't see anything in my mentions, nor can I see your tweets, so I emailed you :).

              As for Google Translate, the issue is I don't see any way to specify languages in the URL; that all seems to happen after you're on the site.


    1. I'll add it in the master next time I update, but it's pretty simple to add to yours now. Just put this in the "User-supplied shortcuts and URLs ** Press Return after last entry! **" step:


      Make sure you press Return so there's a blank line at the end.

      Replace mit with whatever you'd like to use—but note that "m" is already assigned to Macworld, so if you want to use that for Macintouch, you'll have to switch the Macworld one to another shortcut.


      1. I had something close enough to that that I couldn't see the difference by sight comparison, but sure enough, when I pasted yours in, it worked. The one I had created only returned the current main page of the site. Anyway, I'll probably have to read the instructions again more carefully to see what I had done differently. Not too atypical for my experience. Thanks!

  5. Noticed you didn't include a "C" site. I thought of Cheetah 3D forum that I use a lot. Here's the Search URL for my search for "bridge tool, then another for catmull-clark":

    If I use Search Sites from Anywhere after adding
    to the list, I'm brought to the advanced search page where all I have to do is press Enter to activate the search as if I had entered it into the on-page site search field. Is that my best chance to use it correctly, or can you define it precisely from those 2 URLS? Thanks.

    1. In testing their site, it looks like they assign searches a unique number, and that number isn't assigned until you run it. Here's the "after" search URL for catmull-clark:

      That 21610 is the identifier, so even if you then try...

      ...which should search for "testing," you'll find it runs the same search as before, because it's using the ID. So unfortunately, the best you'll be able to do is get to their search page. (You could get fancy and have a KM macro that watches for that page to load then clicks the Search button, but that seems like overkill!)


    1. Yes - once you have 1.2, you'll see there's an update subroutine. When 1.3 comes out, 1.2 should tell you about it. (And it's a nice update—I think I've solved the "how to make it easy to keep customizations" issue.)


Comments are closed.