Select Text, Open Background Tab, Search Website

I agree; I didn't think of that.

That's a good idea. I didn't think of that. Although I tend to prefer approaches that give the user the ability to configure any such features. I'll still ponder your good idea.

I think I probably should do that.

I didn't think of that either... determining if there is selected text. I think I know how to do that. EDIT: I think my macro already does this. If there is no selected text, the macro does nothing.

I didn't know you've done this before. Even if other people have already written macros that do similar things, I still enjoy writing the code myself. Everyone has their own approach and their own ideas, and usually each person comes up with a unique twist. Right now I'm inclined to use dictionaries in all my solutions - they are just so cool.

1 Like

I think there's a slightly better way. In the google search string you can specify that the search must return results from a specific domain. I think the syntax is "" and it's easy enough to see by inspection how to create a URL to include that search string.

I'm aware that each website has its own way of accepting search string data. For now I was just assuming that the data would be at the end of the string. I know that's not the right assumption, but it was a reasonable assumption for purposes of developing a temporary solution.

Now that I have a working macro, I'll probably rewrite it to account for many of these extra little things that people have mentioned today. And it doesn't matter if people use my macro, because I'm really just doing it for myself.

1 Like

The obvious advantage of using two triggers vs a configuration parameter is that the user has both options readily available.

I agree, but my concern was that you said "the dialog could open with...your favorite... site". That's because the term "favorite" probably requires some special configuration that isn't changeable without editing the macro.

I'm still pondering the best solution. I'm trying to write v2 now.

1 Like

Favorite was just an idea, probably a bad one. I think the real options should be: none selected or all selected. I would think that both modes would be used often. If your macro defaulted to all checked, then it would take several clicks to use it in the other mode. And vice versa.

That's very sensible.

1 Like

Yes, I agree. I've started using dictionaries rather than global variables for values that I want to retain between macro invocations. I shared this idea here: Dialog with Dynamic Popup List

Okay I have a new version that is much cleaner in design, making it easier for people to modify for their own favorite websites. Here's how it currently works:

  1. ^X will let you pick a website from a list to search for the currently selected text.
  2. ⌃⌘X will re-use the previously selected website to search for the currently selected text.
  3. ⌃⇧X will open many new tab in Safari using the currently selected text as the search term, one tab for each search engine in your list.
  4. ⇧⌘X will (-when I get it working-) let you edit the list of websites.

It's pretty cool. There are two reasons I don't want to upload it yet. 1) I want to test it for a few hours. 2) I haven't got the fourth item (above) working yet. I can't remember how to write a KM action that lets you edit a multi-line variable. This makes me feel like an idiot. What's the simplest method, can anyone advise me?

1 Like

I'm assuming you have a multi-line text variable near the top of you macro, right?

If so, you can use the following to open your macro in the editor:

Keyboard Maestro Export

As you probably know, you can get your macro UUID by right-clicking, select Copy as... > Copy as UUID.

That's the simplest method I know. If you want to do something fancier, you can put the URL's in a text file. I do this in Markdown Link Tool.

Well, that is certainly "simple". But it's not really any different from letting the user edit the initialization action for the variable.

I might take your advice to have the user edit the value in an external editor.

KM really could use some sort of sophisticated action for editing variables. There's the fancy app from Dan, but that's overkill for what I need. I'm a wiz with shell scripts, maybe I can send my variable to a shell application for editing.

1 Like

The advantage this provides is that the action takes the user to the macro even if the Keyboard Maestro app is not open. Even if the app is open, the user doesn't have to manually find the macro.

Yes, I like your idea and thank you for it. I haven't decided if it's the best idea for me yet.

1 Like

One thing to consider: How often will the user need to modify the URL list?

The reason I use a text files in Markdown Link Tool is that I need modify the files frequently. There are three or more text files (three initially) in a folder and the following options are available to modify the contents:

I'm sure this would be overkill for your application, but the Edit option could be used. That's done with the Open a File Folder or Application action which opens the file with the default application (in my case BBEdit).

I think I have an idea for implementing an editor here. First, I could use a Prompt with List action to let the user pick which line to edit, then I could use a Prompt for User Input to allow the user to edit the line. In fact, the Prompt for User Input is particularly good because I can use it to display the two independent fields of the line in the file (Display Name,Full Address). The only complexity is that I'd need a special pop-up window to ask the user whether they wanted to Add, Edit or Delete an item from the file.

I think I like this idea very much, because it illustrates how to solve a problem with KM (the lack of a variable editor.)

EDIT -- It seems to be all working, including the editing functions. But before I upload it, I'm going to test it for maybe a day. Here are a few screenshots so you can see what it looks like. Your feedback, even your criticism, is welcome.

Here is the window for adding an entry:

Here are the windows for editing an entry:

Here's the window for deleting an entry:

Here's the window that warns you when you attempt to reset the list to some defaults:

1 Like

Not a KM solution, but the free version of Alfred includes the web search feature and I can't recommend it highly enough for this and many other things.


Here is my suggestion, if I understand your request correctly. You can continue to add to this macro using switch case by adding the other hyper key related keys within the macro. That way you don't have to have separate macros. You can use hyper key-y, hyper key-w and hyper key - l in my examples. Switch case and Trigger value remain the key in my example. If I'm off base, disregard. :smiley:

Selection Search.kmmacros (8.7 KB)

Macro Image

1 Like

@Sleepy, I give you an A+ for creativity!

As I mentioned above, I'd go with a multi-line variable. This simple approach provides the following advantages:

  • No KM logic is required, thus the macro is smaller, faster, and less likely to include bugs.

  • Everyone that has KM knows how to modify a text variable. That is, there is a very small learning curve.

  • Even if the URL is very long, one can see the entire URL without horizontally scrolling.

  • If the order of the URL's needs to be changed, standard cut-and-paste methods can be used.

Your feedback is all wise and welcome (especially the A+ part), but since I've already finished the macro, the deed is done, and I plan to post my macro in the Macros page of this website. It may be a little overkill, but I think the techniques I used for allowing users control over a multi-line variable may be of interest to others. It's actually pretty slick. The code is surprisingly simple and somewhat eclectic in terms of techniques used.

1 Like

I may be missing the objective, but I think you're trying to search for a selected string in one of several search engines or websites. I use a conflict palette for that. The same hotkey is used to trigger each macro. A couple of screenshots should explain it.

That's an interesting and different approach.