URL Lookup from within Applications

I can't seem to get a handle on the wild-array of possibilities.

I copied the Open Webster Macro to a new "LookUp Group"", as I thought that would be the
easiest way fro me to get going. I created several (4) macros using the Webster Lookup as a generic, where I could repeat each generic lookup wheter, Definition, Thesaurus, Google search, etc.

Within each of my macros, I set availability to encompass Applications such as
Preview, Evernote, Brave, Chrome, Pages, WORD, BBedit, etc.

I was trying to a universal method for Dictionary/Thesaurus functions from whatever common
Apps I might have at hand. My thoughts were, if any of these Apps had placed text into the
Clipboard, I could invoke this look up trigger menu and choose, Definition/Thesaurus, or whatever.

My trouble is, I can't seem to figure out how I should go about triggering the Group Palette.

For a while I had successfully created a Palete Style that worked, but the unique first
letter didn't work, then I've doen something that left the palette Menu Bar running
(spinning) and I can't seem to get it to stop it, or, Trigger my way out of this loop.

I thought this should be easier, I must be missing the concept behind the Macro Group function.

Also, I looked at the OPEN URL Macro posted for Google Chrome which has a note about substituting DuckDuck... However, that looks complex, where my start was to be 4 macros, in a Palette menu, allowing me to choose Thesaurus, Dictionary or other lookup site, and Bingo!

Do you mean if the user presses CMD-C to copy the text while working in the app? Most of the times apps don't place text into the clipboard, because they leave that to the user. If that's what you mean, then all you have to do is write a KM macro that captures the CMD-C key, and sends it back to the app while also processing the data in the clipboard. Here's how I would start:

Inside that If action you could show the palette.

I assumed a CMD-C put something into the Clipboard. I also assumed that since I can Cmd-C in Word, Pages, Notes, Brave and nearly anything else, I could then decide to Trigger a Lookup. Since, I know what I put into the Clipboard, and I know why I saved it it seems that a Trigger for a Palette Menu would allow me to search for a definition, a synonym, a maps.google location, or a browser search.

So, I was looking for a key that was widely available, i.e., not used. I choose Cmd-L to trigger each of the various simplistic macros. Using the Webster version as my goto template, I do the same in all three of these Macros: (see image upload KM-1.jpg)

Also, Airy, one other bit of my confusion comes from the idea of a Group (Palette).

I put the Cmd-L as a trigger as seen here: (Upload KM-2.jpg) but this means I've gone trigger happy, No ??

I found better examples to use with regard to passing parameters to a browser.

These 3 macros all work correctly using this method:

So, they are all very similar in that they simply concatenate the Parameter onto the URL

But, I'm not sure about how the palette option is supposed to work...

Thanks,
-D4Linthicum@gmail.com

Take a look at.Literary Toolbox here. It provides those functions across many apps.

The method I proposed for you will intercept the CMD-C, but if you look again, the first thing it does is re-submit the CMD-C, so you won't lose that functionality. But if you want to use two characters, that's not a problem. It might be safer.

There's no wrong answer. It looks like that will work, too.

If you say that they work, there's nothing for me to add. But it looks like you are forgetting something important. If you are passing data to a browser, you probably should convert your text using the Km Filter called "Percent Encode for URL". If you don't do that, some of your calls will end up failing.

I would suggest that you consider using Apple's built-in Dictionary/Thesaurus. Try this action. I think you will like the results.

image

The result will be instantaneous.

1 Like

I have been trying this out but cannot make progress... If I have a local variable term set to a word that I want to look up, the following Applescript (modelled on an example at: AppleScript [Keyboard Maestro Wiki]) results in "term" being defined.

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set term to getvariable "Local term" instance kmInst
end tell
open location "dict:///term"

Airy, KevinB, Thanks!

I see the notable speed difference, but I still prefer all of the optional functionality of the Webster version. Great suggestion, tho...

Now the last part: Note all of the CMD-L functions I have created. I would like some input on creating a CMD-L "LookUp Palette". However, I don't see how to make the connections. I was trying to place all of these macros into a group, and trigger the group, but that doesn't seem to work.

Does anyone have an example of a functioning Palette?

I've been reading about the Palette Organizer v1.3 but don't see the KMMacro file anywhere for download. Where do I find it?

Thanks!!

It's there at the top of the thread

And here's the thread:

There's no interpolation in AS -- you have concatenate your string and variable the old-fashioned way:

set kmInst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set term to getvariable "Local term" instance kmInst
end tell
open location "dict:///" & term

Of course, you don't need the AppleScript at all -- just use the "Open URL" action:

image

2 Likes

OK - Thanks! - I went scrolling down looking for a later version when I should have just taken the One off the Top. My apologies...

This is the result of executing the Macro:

Error in 'KMWindow':
Variable 'Local_MacrosInfo' not set
Error in 'setupUI':
undefined is not an object (evaluating '_macrosInfo.groupName')

JavaScript problem or...?
I see this variable is the result of a JavaScript routine but this is where my knowledge ends...

I had added the "01) - 03)" prefixes onto my Macro names and Pal Org. v1.3 gave me the error message from above.

I did a search for "Local_Macro..." and my display changed to:

But, these individual macros all look the same after I remove the Search Parameter.

Can someone help explain the how/why this works like it does?

Oh, wow. Did I ever say I learn something from you every day? Thanks.

You need to select two or more macros, then launch the Palette Organizer macro using a hotkey, or from a palette.

Yes Dan,

I had all three selected in the Macro window for the Group...

Do you use more than one editor window? And what version of macOS are you using?

Thank you! Both methods work.

For anyone who might like to know: dict:// or dict:/ may be used instead of dict:/// (this is in line with IETF RFC8089 from 2017).

When I first mentioned "dict:///" I was just copying an example that I had found on the internet. It looked strange, but it worked. Thanks for doing more research.

1 Like

I now precede this action with a filter action set to "Percent Encode for URL". You will need this for words such as naïve and soupçon. :wink:

2 Likes