This is a macro to help people who want to select text in an app and then trigger a search using a hotkey for a variety of search engines using that text. It uses a few different techniques and actions that might be good to learn from for people who are learning KM. I enjoyed writing it. It doesn't matter to me if people use it, but I'm willing to consider changes or new features if people ask.
Please read the opening comment in the macro to learn how to set up some default search engines before you start using it.
Give me a minute to validate the upload was correct.
EDIT: okay the macro is loaded into a folder called Testbed. It sounds like you found it. Then in order to run it you may have to enable it. I think when you download macros, they are disabled by default. Then inside my macro it says what you should do before you run it. here's what it says. Specifically make sure you read the large paragraph #2 below.
This macro was released by Sleepy on 26 Feb 2021. You should read this before running this macro.
Basicaly, it represents a series of four hotkeys that let you do four different things on any text that you have selected in any app:
Press a hotkey to search for the text in the last search engine you used;
Press a hotkey to search for the text in a search engine of your choosing;
Press a hotkey to search for the text in each of your saved search engines;
Edit your list of search engines (Display, Add, Delete, Edit)
Here are three points to consider:
If you change the hotkeys, you must also change the strings above the green boxes below. Be careful: in order to get the correct string name, you will probably want to enable the red box below so you can copy the new hotkey's string into this macro.
The first time you run this you should set up your default list of search engines, which in this macro is done by pressing ⇧⌘X and then clicking on the Default button. This will set up your global variable of search engines.
This macro has short series of actions you can find in the "otherwise" clause near the ottom of this macro. This is essentially a programming trick to allow all this code to be placed in a single macro. This macro calls itself recursively instead of using a subroutine or duplicating the code in this macro. I'm not sure if this is how KM was meant to be used, but it's a neat trick that people who program in KM should consider.
P.S. Let me now if you find bugs or have new ideas to add to this.
I used to be a snooker player a long time ago (high break 143). Then I transitioned to 8-ball and 9-ball (national champion a couple of times). That avatar is something that my best friend and I created in one long night when we were trying to open a pool room.
Thanks for sharing, @Sleepy. I really like the way you have provided the three modes for searching: last used, user choice, or all. I'd say another A+!
I already weighted in on the editing part, so I won't do that again.
I see that you are using a global variable (SearchWebsites) to store the website Labels and URL's. You had mentioned the possibility of using a dictionary, but in this case a global variable is an excellent choice as it provides a nice backdoor for those that want to paste in a group of websites.
Here's a list of search URL's that I've collected for those that might want to add others:
Maybe someone else knows where such a list might be compiled on the web. I think I got many of the above from LaunchBar.
If you are interested, I have some ideas with respect to naming global variables and dictionaries:
Naming Global Variables and Dictionaries
For persistent data, I've generally moved away from storing persistent information in global variables in favor of dictionaries. However, when I do use a global variable, I name them as follows:
jsXXX_YYYY where: 1) js are my initials; 2) XXX is a short acronym or abbreviation for the macro; 3) YYYY is a description for the variable. For example, suppose this macro was mine, I would name the global variable: jsSEP_SearchWebsites
This convention provides the following:
It's highly unlikely that my global variables will collide with variables from another macro.
In the Keyboard Maestro Preferences > Variables all of my global variables are grouped, first by me (js), then by macro. This grouping makes it very easy for me to clean up the global variables if I decide to retire a macro (or upgrade one by moving from global variables to a single dictionary).
Since dictionaries are also global (even if they are harder to see—since they are not in the Preferences), I use a similar naming convention. For example for this macro, I'd use: jsSEP_dict and have a key named SearchWebsites.
You put a lot of thought into that post. I'm very impressed with your long list of search engines. That will help a lot of people. Perhaps now I should add those into my macro as the default values, and find a way to allow users to delete them. Or people can just refer to your excellent list and add them as they see fit. Let's see if anyone uses this macro and likes it. Maybe they will have ideas for upgrades.
If I recall, I think I used the variable instead of a dictionary because I was just using the quickest solution at the start, and didn't think to use a dictionary as I progressed. Perhaps a dictionary is overkill in this case. Maybe a future version of this macro might use a dictionary.
Your idea for naming persistent variables is good. I may start thinking about doing that myself.
I think I wrote that whole macro in one quick sitting. It turned out pretty good: there are some cool techniques in there. One technique that probably qualifies as a "hack" is how I implemented a subroutine in the same macro. In fact, now that I've done that, I can see how to expand that so that multiple subroutines, even with data being passed to them, can all be implemented in a single macro. Some people may prefer multiple macros for clarity, but in a short macro like this, it's probably not a big issue. But I'm waiting for someone to examine my macro and ask me how that subroutine works.
Hmm, I just noticed a spelling error in the title of my Comment at the top of my macro. Not worth fixing.