Using Keyboard Maestro to jump to a web browser tab

Hi there,

I was wondering if anybody knew of a way to accomplish this in Keyboard Maestro with an AppleScript?

In either Safari or Chrome, I’d love to press a keyboard shortcut that would look at all the open tabs (in my frontmost browser window).

As soon as it finds a tab that is already opened to any page from the domain, I would love to jump to that already-opened tab. (It might be a page from different subdomains -- it might be a page from,,,, etc.)

However, if it doesn’t find any tabs that are already opened to the domain name, then I would love for it to create a brand new tab that opens to the homepage

Thanks for any insights that you might be able to provide! :slight_smile:

AppleScript is a great thing that usually provides optimal answers, but AppleScript is rarely the only way to solve problems. Why do you want AppleScript as your solution?

I think I can see a way to do it with native KM actions, but I don't want to investigate that if you really need or want AppleScript. I can tell you right now that my KM solution will probably cause the "visual effect" of activating each tab in order to be able to "read" the address in the tab. But it should work very quickly. Basically my solution would be using the "Next Tab" action to activate the tab, then use the "FrontBrowserTitle" token to get the token name. And if the returned value meets your requirement, it would stop there but if it kept going and started repeating, it would stop and create a new tab as you desire. It wouldn't be a very long program. I have never used KM to manipulate browsers so I'm in unfamiliar territory, but I think it could work.

Hi @Airy!

Thanks so much for your reply!

Oh, and so sorry for my misleading question — I actually didn't care at all if my solution was based on AppleScript.

I was just ASSUMING that AppleScript was the only way to go, because I couldn't figure out how to do it natively with Keyboard Maestro's native actions. :stuck_out_tongue_closed_eyes:

But it sounds like you might have figured out a way to do it with KM's native actions! That would be incredible, and would be even better than AppleScript because it's all built into KM!

Ok let me take a quick stab at it now. I'm no expert at this, so I'm not 100% certain I will succeed. I am more familiar with other parts of KM, but I'm happy to try this now until I need some sleep.

Haha, thank you so much for attempting this challenge on my behalf! :slight_smile:

Okay, I wrote up a routine and it seems to be working. It had no bugs (but I didn't test it thoroughly, so it might have bugs I didn't notice.) Hmm, I just noticed it works only with Safari, but that would take only a minute to fix. I've uploaded the program for you below.

Before I change it or fix the part that it only works with Safari, I'd like you to load this macro and test it out yourself. There's a good chance that you can fix it to work with both Safari and Chrome without my assistance. HINT: You don't need to add any new statements, all you need to do is modify any statement that refers to Safari and replace it with a statement that works with "FrontBrowser". If that's too much for you, I'll fix it tomorrow. But to be honest I like to challenge people to try things. And so this is your challenge: "without adding any statements, modify the program below to work with both Safari and Chrome."

Find an Apple URL in the tabs of the Safari browser Macro (v11.0)

Find an Apple URL in the tabs of the Safari browser.kmmacros (4.6 KB)

P.S. I didn't mention it, but the group that this macro was stored in has a flag that says the macro is active only when Safari is active. That's probably the case for you anyway, so you may not need to set that flag yourself. It's just a warning for you.


This prior thread is probably worth reading:

1 Like

Perhaps you could use AppleScript's UI scripting to query Safari's menubar - if the titles of the tabs are visible in some submenu of some menu item.

Hi @Airy,

You're a genius!! :star_struck: :raised_hands:

Not only did you perfectly solve this problem for me, but I also undertook your personal challenge, and I was able to edit the macro to work with ANY browser that is the frontmost browser window! :smiley:

Thank you sooo much for guiding me through this perfectly!! :sunglasses: :muscle:

I've attached the macro below, along with a screenshot of my setup.

Find an Apple URL in the tabs of the frontmost browser window.kmmacros (5.3 KB)

1 Like

Thanks. Very nice to hear your words. I was worried you might be angry for me not fixing the macro myself.


Lol, how could I be angry when you went out of your way to volunteer your free time to solve this problem for me!? :stuck_out_tongue_winking_eye: I'm very grateful!

1 Like

@scotty321, here’s another macro that you might find interesting: Activate, Reload, or Open Browser Tab