MACRO: Abbreviation-Based Web Searches

Thanks Rob, I understand. I'll try to come up with my own macro for multi searches.

While not nearly as fancy as Rob's impressive macro, it's not too hard to put together something that can do multi searches:

[Example] Copy Selected Text and Search Multiple Sites.kmmacros (2.3 KB)

2 Likes

While it may seem I've been quiet lately with Web Search via Shortcut, that's not the case at all. It's just that I was frustrated by how hard it was to keep my own copy of the macro customized, given how often I was updating it, and having to always have a clean copy ready for distribution.

So I set out to rebuild it from the ground up, with a few objectives:

  • Speed. While the old macro wasn't all that slow, there was just a bit of a delay between invoking it and seeing the input dialog.
  • Shortcut Management. It's a real pain having to open the Keyboard Maestro editor and directly update variables to make changes to your shortcuts. And it's a real pain when an update comes out, and you have to copy-paste all your work between the old and new macros. I wanted to get rid of all that.
  • Ease of use. This is tied into easier updating of your shortcuts, of course, but I wanted an easy way for users to be able to add shortcuts without having to go dig up their own.

So instead of trying to make 2.5 do all of those things, I threw away pretty much all of it except for the actual input processor, and started working on 3.0. It is not quite ready, but it's close, and I'm looking for some testers — if you'd like to test it, just reply here and I'll give you the URL. Do not delete your existing 2.5 macro, just disable it (or assign it to another shortcut).

It addresses all of the above; here's a teaser for the speed side—this is how long it takes for the dialog to appear after you hit the hot key:


The new input dialog appears basically instantly, over 5x faster than the old. And as for management of shortcuts, that's now 100% within the macro, not in the editor at all:

The current version is nearly fully functional, but it needs a lot of polish, as well as some how-to instructions, etc. But I'd like others to use it, to help find things that I know I've missed. So reply here or message me, and I'll send you a link and some basic instructions.

Many thanks to @Lantro for his invaluable assistance in getting to this point—this macro is just a bit more complicated than the 2.x series (28 macros vs 10 macros). Without his help, I'm not sure I would've gotten here :).

-rob.

Whoa, this is amazing! I have in fact gotten ahead of the dialog a couple of times, typing my search term before it was ready for me, so the speed increase is great news.

I hadn't been going to bother you with it, but so long as you're massively revising anyway: if I search for a "quoted phrase," the macro works if I include the search site shortcut, but chokes on the quotation mark (I presume; a "search regular expression" action throws an error) if I omit it to use my default. (Google. I know, I know, don't @ me.) If that's easily fixable, great; if not, it's not that hard to include the shortcut.

I'm happy to test the new version, but tbh I wouldn't really be putting it through its paces; I really like the macro but I don't run it that often, and usually on the same site. LMK if I can be of help; otherwise I'll just happily anticipate.

That should be a simple fix ... yep, simple, and now fixed. So it'll work in 3.x, and I may push a final 2.6 update to fix that (and which addresses a couple other things).

Thanks for the heads up!

-rob.

And 2.6 is out now, with the default search quote fix, and a couple other things—one minor, one pretty major.

The minor one is that the search dialog now appears on the display with the mouse, instead of the display with the frontmost window. I found, at least on my multi-display setup, that my eyes are more often where the mouse is than where the frontmost window is. Maybe in 3.0 this can be a pref.

The major change is that the number of active default shortcuts is down from over 40 to just 18—I figure nobody uses 40+ shortcuts. But I didn't delete them; open user-Shortcuts, and you'll find those (along with a bunch more), mostly ready to go. Just copy, replace the ?? with a shortcut of your choice, and paste into your additions box.

This was partially to better match 3.0, which has that same smaller set, but also because it was just silly to include 40+ enabled by default.

As mentioned above, 3.0 is imminent, so this is the last 2.x release.

-rob.

And 2.7 is out now, due to me stupidly—but accidentally—changing the keyboard shortcut in 2.6.

-rob.

It's finally done…well, done enough to release to see what wasn't actually done. 3.0 is out now, and should show up as an update if you check from 2.7's updater. I've also put the new version in the first post in this thread.

As stated above, the dialog shows up nearly instantly now, and there's an in-macro Shortcut Manager for handling all shortcut-related tasks. There's also an online help page to get you started, and help those who need to migrate custom shortcuts to the new version.

This is, by far, the most complex macro I've ever written—the Shortcut Manager side is much larger and more complicated than the macro itself, but the end result is something that should be easily updated in the future; there won't be anything to do to migrate customized shortcuts when a new release comes out.

If you do try it, please let me know what issues you run into—even though @Lantro (thansk for all the help!) and I did a lot of testing, I'm sure there's stuff we missed. How much testing? Well, here's my macro usage counter report covering some of the version 3 builds...

That's a lot of web searching without actually ever searching the web! :slight_smile:

-rob.

1 Like

@griffman, just downloaded v3.0 and am checking it out.

First impressions: WOW, very polished design and high quality documentation! Great work on the implementation of user-modifications.

If I do encounter any issues I'll certainly let you know. Thanks so much for sharing your hard work.

Thanks for the comments! I'm pretty happy with how the Shortcut Manager turned out, working within the constraints of Prompt With List (i.e. can't capture the Escape key cancel).

-rob.

Hi Rob,

I have just loaded and installed the macros. Thanks first for all of your work!

As I am from Germany, I'd like to adapt some searches and direct them to German pages. But so far I haven't managed to do that yet...

I am proceeding as follows: I call up the Manager and select "Modify a shortcut's settings" there.

Then I select the shortcut, e.g. Wikipedia:

There I change the URL to "https://de.wikipedia..."

As soon as I click "OK" I get the following error message:

A change does not take place, I can only create a new shortcut.

Michael.

Whoops, that may be a bug. I'll do some testing, and thanks for spotting it. For now, first use the Remove feature to remove Wikipedia, then add a new W shortcut.

-rob.

1 Like

This is how I did it already :stuck_out_tongue_winking_eye:

Version 3.1 is out now; check for updates within the Shortcut Manager, or download via the link in the first post above.

This fixes the "can't modify without changing the shortcut" bug, and makes a couple other minor changes.

-rob.

1 Like

So, now I had the opportunity to install the update and: it works like a charm. Thanks a lot, Rob!

Thanks!

-rob.

3.2 is out now (linked above, and check for updates in the macro). I found a couple glitches in the remove and modify routines; those have hopefully been squashed.

-rob.

1 Like

And ... 3.3 is out, sorry!

The fix I made in 3.2 had unintended consequences and broke stuff elsewhere (specifically when modifying and/or removing built-in shortcuts). This release both fixes the bug and repairs any damage that 3.2 might have done to your ws_deletes.txt file. Please let me know if you have issues with this version!

As a related note, this is (hopefully!) the final release in the 3.x series. As I was writing the 3.0 version, with the in-macro shortcut manager, the amount of regular expression manipulation I had to do to make some things work was just so complicated. Even as I was writing it, I was worried about maintainability. And both of the recent bugs were directly related to the regular expressions not doing exactly what I thought they would be doing.

As just one example, this is just part of the code needed to display a list of disabled built-in shortcuts:

And the 3.x macro is littered with probably 100+ sections like this, all needed to split and deal with the various shortcut types (built in, optional list, or user added). Version 4 migrates the entire back-end of the macro into a sqlite3 database—sqlite3 is built into macOS, and it's really fast and supports SQL queries. So I'm able to replace the gibberish above with something like this:

select shortcut, descrip, url from TheShortcuts where
(source='DEFAULT' and status='INACTIVE');

This is so much easier and more maintainable ... yet again, it's how I should have written it in the first place. No more text file manipulation, either; records get read from and written to the database itself.

To keep the speed up, the database is only accessed when necessary—once to set a global variable with the active shortcut list, and then when you make any changes to your shortcuts. Just using the macro, though, the database is never touched, so this version is just as fast as the prior—and actually faster when changing things, because there's so much less text manipulation to do.

The macro itself is done; I'm writing the converter that will migrate the 3.x files into the database, so you won't have any work to do when you upgrade.

-rob.

5 Likes

Following up a long time in the future with an announcement that contains both bad news and good news.

First, the bad news: This macro has reached its end-of-life at version 3.3. I found it nearly impossible to maintain and update, given the complexity of manipulating the text strings in the files I was using to track shortcuts. If you're using it, it should continue to work fine, but there won't be any more updates.

Now, the good news: I have rewritten the engine behind the macro, switching from text files to a sqlite3 database. This let me remove hundreds of commands, many of which contained scary regex. And although the new macro looks identical to the old, the UI is really the only part that hasn't changed. Given how much is new, I chose to branch to a new macro, so ... if you want to try the new macro (both should coexist just fine), check it out here:

Quick Web Search 1.0

There is one additional bit of bad news: I wasn't able to write a functional importer to move your customized shortcuts from the old macro to the new macro. I tried, I really did—that's what was holding up the release. But every time I thought I had it working well, I found another issue. In the end, it just wasn't feasible (for my skill level), so I had to leave it out.

So you'll have to customize your shortcuts one more time in the new macro, but those changes are then stored in the database, and should be good through all future updates (famous last words, I know).

Anyway, thanks for the feedback on this version, and if you try the new one, please let me know how it works for you.

-rob.

3 Likes