MACRO: Abbreviation-Based Web Searches

I wound up going in a slightly different direction:

That way, the only thing I'm grabbing is line breaks, which I think seems a bit safer—is there a downside to doing it that way you can think of?

-rob.

Nah, it's just that my reflex is always to clean up extraneous whitespace as much as is easily possible, and I can't imagine a circumstance in which it would be important to pass a series of whitespace chars to the search instead of just one, so out they went. (It's unlikely to make a difference, but if there's a series of newlines, then using \n will produce a series of spaces, so you might as well use \n+. And now I'm wondering if there might be any circumstances in which a tab character could foul the search it gets passed to? Little Bobby Tables strikes again...)

Good point on the \n+, changed. As for whitespace, I take a different approach when I don't know what the input is: It's not mine, so I try to mess with it as little as possible. If something breaks, then I'll attack that problem. Your way is notably better in terms of preventing breakage :).

-rob.

This is very cool. Great work!

I am still exploring, but I did notice the urls for Google Image (gi) and Google Maps (gm) may be reversed. In other words, gi → google maps and gm→ google images.

I just caught the map one tonight, but missed images. Will be fixed in next update; thanks!

-rob.

Version 2.3 is out, and the most important change is that this version sets it up so that future macro updates (downloaded within the app) will be verified after download. I added this to insure that if someone hacks my server and replaces the downloadable macros that users won't install those evil files.

How does this work? I store a SHA-1 hash value (basically a cryptographic signature) for each version I release on Github. When you download from my site, I calculate a SHA-1 value for that download, and compare it to the value stored on Github. If they differ, there's a problem. This may not be perfect defense, but it would require someone to get into two different systems if they wanted to replace my downloadable macros in an undetectable manner.

The update checker is much simpler now—it's independent of the main macro's code, and runs every 14 days. But if you read that I've released an update, you can just run the update macro directly to get it.

-rob.

2 Likes

Version 2.4 is out, and features an optional "no text" input dialog, and the ability to search one site without using a shortcut—both shown in this screenshot:

It's also much faster (about 8x faster!) at matching your typed shortcut to the list of possible shortcuts, meaning that the browser will open quicker after you press Enter/click OK.

I've updated the main download link in the first post above, or just run the "Update check" macro in your current version of the macro.

Edit: This is also the first "real world" test of the download verification system. Everyone running 2.3 who upgrades to 2.4 should be asked to verify their download. It worked fine here when I upgraded my 2.3 installation, so please, let me know if you have any issues with it.

-rob.

1 Like

One day later, 2.5 is out with a bug fix and (more usefully) a "check for updates" button on the Help screen, so you don't have to open the Keyboard Maestro editor to manually check for an update.

-rob.

2 Likes

Thank you for this great macro (suite)!

I notice one strange thing: when I'm in space 1 on my primary screen, the macro pops up at screen 2.

When I'm at space 2 etc. at screen 1, the macro also pops up at screen 2 but is immediately repositioned to screen 1.

My secondary screen is positioned at the left-hand side of the iMac:

BTW: Posted this at Proz (a site for translators):
https://www.proz.com/forum/apple_mac_operating_systems/355496-abbreviation_based_web_searches.html

It should be appearing on the screen with the majority of the frontmost window, at least based on what I've read in the Keyboard Maestro documentation. I'm using this calculation to find the center:

KM defines "Front" as "the screen containing (the most of) the front window," so you should see it appearing on whichever display has most of the frontmost window. Is that not what's happening?

Edit: I think I'll change it to "Mouse," as this is probably a better representation of the active screen.

-rob.

1 Like

How to add a trailing sequence to the URL?

E.g.:
Start=https://iate.europa.eu/search/byUrl?term=
Finish=&sl=it&tl=en

To get: iate

Where 'Bolzen' is the word that you want to search.

IA•IATE - German to Dutch•https://iate.europa.eu/search/byUrl?term={search}&sl=de&tl=nl

Works fine. Great!

My current set of user-defined searches:

DP•DeepL D-NL•https://www.deepl.com/translator#de/nl/{SEARCH}
DPND•DeepL NL-D•https://www.deepl.com/translator#nl/de/{SEARCH}
DPNE•DeepL NL-EN•https://www.deepl.com/translator#nl/en/{SEARCH}
GL•Glosbe D-NL•https://glosbe.com/de/nl/{SEARCH}
IA•IATE D-NL•https://iate.europa.eu/search/byUrl?term={search}&sl=de&tl=nl
SP•Spelling NL•https://woordenlijst.org/#/?q={SEARCH}
WD•Wikipedia D•https://de.wikipedia.org/wiki/{SEARCH}
WN•Wikipedia NL•https://nl.wikipedia.org/wiki/{SEARCH}

Yep, that's how you do it :).

-rob.

Hey Rob,

Do you have any plans to allow simultaneous searches on multiple websites?

I currently have no idea, how to fire them. Perhaps via groups?

Perhaps this would be a useful addition/setting for other users too:

  • If GetClipboardContent=True then the clipboard content is pasted and selected in the Search field.
  • The user can press :arrow_upper_left: and type 'w ' to search the word in the Wikipedia, or
  • The user can just start typing, overwriting the selected text.

I do not—that would be an implementation nightmare. In theory, you could do it by allowing something like...

shortcut1#SEPARATOR#shortcut2#SEPARATOR#shortcut3 search terms

Where #SEPARATOR# is something that won't ever be in a shortcut, i.e. a couple of unicode characters or something.

However, implementing that is not something I want to even consider doing, given the amount of work involved and my personal lack of need for such a feature. If I have to search multiple sites, I'll just send it to DuckDuckGo :).

-rob.

This would also be something of a nightmare to implement, especially with automation where a user might not have on the clipboard what they think they have on the clipboard. Given you can use the clipboard by pressing Command-V in the input box already, that's easy enough access to the clipboard for me.

-rob.

1 Like

Yes, but what if the user has some text selected and then launches your shortcut? That would be a more intentional user step and be very handy. (This would be in the spirit of PopClip for Mac.)

I use that approach in a shortcut I created and use many times a day (and even while typing this post :grinning:): Augment or Filter Text

More recently, I added that feature to Log It. If you are interested, the logic might be easier to follow in that macro.

I still think it's too much complexity to add—I'd have to borrow your code to find a selection, which isn't something that's trivially done, versus just asking a user to press Cmd-C before they launch the macro.

(It'd be great if you could rely on the presence of the Copy menu item to determine a selection is active, but many apps ignore that practice now.)

As it is now, the logic already has too many layers to make me comfortable, and I don't want to further complicate things. If someone wants to do so on their own, more power to them ... but it's more complexity than I want to manage :).

-rob.

1 Like

Fair enough. Beggars can't be choosy! :rofl:

I agree it's not bullet-proof, but I'm generally using both in the context of a browser, so it almost always works.

Sadly, I usually use in the context of a text editor, and it fails badly with VS Code.

-rob.