How Do I Search URL of All Safari Tabs and Make Found Tab Frontmost?

Hello,

I'm trying to make a simple macro to search between Safari Tabs. I have everything working from different pieces of codes I found around the forum and I managed to create a user input form that asks for a portion of the domain name it needs to look for from the Safari tabs.

But I would like to avoid using a visual input form and just to let KM listen the typed string after I press the hotkey trigger. So I could just press Command + Y for example, type "maestro", press enter and let it open this tab where I am writing right now without having anything appear on screen before the tab gets opened.

I tried to search everywhere for a way to save typed text in a variable but I haven't been lucky. How could I do that?

Thank you,
Gabriel

I also thought about doing It with a typed string trigger, with regex (for example .stmaestro, .stgoogle, etc) because I saw there is a variable for the trigger so I could just clean it and extract the real search term. That could be an option too I guess, but I would prefer the one in the OP.

The below Macro provides an example of how to do this.

This seems like a contradiction in terms to me.

  • CMD-Y would trigger the macro
  • But then you need a Prompt to receive the typed string "maestro"
  • And then "press enter" would close the prompt and continue execution of the macro.

So, it being unclear as to what you actually want, I have provided a macro that will work with either a Typed String trigger, or with a HotKey Trigger.
Remember that if you use a Typed String Trigger, you MUST type it into a document or text area that accepts text entry.

The "Prompt for User Input" is required if you use a HotKey Trigger, but not if you use a typed string trigger.

Using the Prompt has the advantage of remembering your last search string.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Search Safari for Text in URL [Example]

**Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/a/1/a17527c86b327af7a75c8e977c06076d2d0f07dc.kmmacros">Search Safari for Text in URL [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

This macro was also uploaded with a typed string trigger (between the quotes):
"`;sf\.[^ ]+ ` "
Note the SPACE at the end.

So, to search for text in the URL, you would enter, for example:
`;sf.TextToFind `

You can change the "sf" to any other characters you want, except for a PERIOD and SPACE.

---

### ReleaseNotes

Macro Author:  @JMichaelTX

This is just an example written in response to the below KM Forum Topic.  You will need to use as an example and/or change to meet your workflow automation needs.


**MACRO SETUP**

* **Carefully review the Release Notes and the Macro Actions**
  * Make sure you understand what the Macro will do.  
  * You are responsible for running the Macro, not me.

**==USE AT YOUR OWN RISK==**

* While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
  * **Ask first**
  * Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

Topic Title:	Save in variable the typed string

URL:  https://forum.keyboardmaestro.com/t/save-in-variable-the-typed-string/16929

Post Date:  2020-02-09
Posted By:  gginer

I'm trying to make a simple macro to search between Safari Tabs. I have everything working from different pieces of codes I found around the forum and I managed to create a user input form that asks for a portion of the domain name it needs to look for from the Safari tabs.
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

<img src="/uploads/default/original/3X/6/6/66eb31ec08dad2f9e31c128efcab4e2e0cf0288f.png" width="603" height="1366">
2 Likes

Thank you very much. Working perfectly!

1 Like

I hope you don't mind that I have revised your topic title to better reflect the question you have asked.

FROM:
Save in variable the typed string

TO:
How Do I Search URL of All Safari Tabs and Make Found Tab Frontmost?

This will greatly help you attract more experienced users to help solve your problem, and will help future readers find your question, and the solution.

1 Like

No worries :slight_smile: Thanks again