MACRO: Select or Open a New Browser Tab, v5.0

Note: This macro has been renamed and significantly improved. Prior to v5.0, it was named Activate, Reload, or Open Browser Tab. If you are transitioning from an older version, please refer to the UPGRADE AND INSTALLATION INSTRUCTIONS.


PURPOSE

This macro will open a URL in: Safari, Orion, Chrome, Brave, Edge, Vivaldi, Arc, or Firefox. In the simplest case, if a URL is already open in a browser tab, then that tab will be selected rather than opened in a duplicate tab.

The exact behavior of this macro will depend on one or more specified browser action keys—a compact instruction that tells the macro which browser to use, which URL to open, and how to handle existing tabs. See BROWSER ACTION KEYS for more information.

The macro is normally triggered by another macro using the Execute a Macro action. The invocation spec is set using the With Parameter in the Execute a Macro action.

Alternatively, the macro can be triggered, and the invocation spec supplied, via AppleScript (e.g., by Alfred or Bunch). See CALLING MACRO TEMPLATES for more information.


QUICK START

The examples below demonstrate how to use this macro as a sub-macro called from other macros. Each example shows an invocation spec passed via the With Parameter field of the Execute a Macro† action.

†To create an Execute a Macro action, right‑click the macro and choose Copy As → Copy as Execute a Macro Action. After pasting the action, reveal the With Parameter field using the gear icon in the upper‑right corner of the action.

Example 1: select/open a URL

From another macro, use an Execute a Macro action to trigger this macro; specify the URL using the Execute a Macro With Parameter.

https://forum.keyboardmaestro.com/latest

If a Safari† tab is open to the URL, it is selected. If not, a new tab opens to this URL.

†Safari is the preferred browser, but the preference can be changed—see MACRO SETTINGS.

Example 2: select/open a URL with a specified browser

Like above, but additionally, specify the browser application using a leading single letter† and colon.

a:https://forum.keyboardmaestro.com/latest

If an Arc tab is open to the URL, it is selected. If not, a new tab opens to this URL.

†Supported codes: s (Safari), o (Orion), c (Chrome), b (Brave), e (Edge), v (Vivaldi), a (Arc), f (Firefox).

Example 3: select a Url tab or one from the same domain

Use YAML format to specify multiple keys.

Browser: Edge
Url: https://forum.keyboardmaestro.com/latest
UrlPattern: --domain†

If an Edge tab is open to the Url, it is selected. If not, and if an Edge tab is open to the Url's domain††, it is selected. If not, a new tab opens to Url.

--domain, or alternatively -d, is automatically expanded to a case-insensitive representation of the Url domain. In this case, that would be: (?i)^https?://(www\.)?forum\.keyboardmaestro\.com(?:/.*)?$

††In this example forum.keyboardmaestro.com

Example 4: match any tab from a website path and replace it with a URL

Browser: Arc
Url: https://github.com/home-assistant/core/issues/161212
UrlPattern: https://github.com/home-assistant/core.*
ReplaceMatched: 1

This finds any open Arc tab matching https://github.com/home-assistant/core.* and changes it to the specific issue URL. If a matching tab is not found, a new tab opens to Url.

Example 5: confirm keys

Browser: Edge
Url: https://apple.com/macOS
UrlPattern: -d
DryRun: 1

This processes the invocation spec and, because DryRun = 1, echoes the resolved browser action keys without actually opening any browser tabs.

In this particular case, the following would be displayed:

𝗦𝘁𝗮𝗴𝗲 𝟭 𝗢𝘂𝘁𝗽𝘂𝘁
𝘽𝙧𝙤𝙬𝙨𝙚𝙧 𝘼𝙘𝙩𝙞𝙤𝙣 𝗸𝗲𝘆𝘀: 𝗡𝗼𝗿𝗺𝗮𝗹𝗶𝘇𝗲𝗱 𝗳𝗿𝗼𝗺 𝗜𝗻𝗽𝘂𝘁 𝗦𝗽𝗲𝗰, 𝗣𝗿𝗲𝗳𝗲𝗿𝗲𝗻𝗰𝗲𝘀, and 𝗜𝗻𝗳𝗲𝗿𝗿𝗲𝗱/𝗗𝗲𝗳𝗮𝘂𝗹𝘁𝘀

Browser: Edge  ##> input
Url: https://apple.com/macOS  ##> input
NewWindowAlways: 0  ##> preference
NewTabAlways: 0  ##> preference
ReloadTab: 0  ##> preference
UrlPattern: (?i)^https?://(www\.)?apple\.com(?:/.*)?$  ##> input converted to regex
TitlePattern:   ##> default
MatchLogic: url-only  ##> inferred
ReplaceMatched: 0  ##> preference
NewWindowIfNotFound: 0  ##> preference
DryRun: 1  ##> input

Next Steps:

  • See INVOCATION SPEC FORMATS for supported input formats
  • See BROWSER ACTION KEYS for the complete list of available keys
  • See Regular Expression Patterns for pattern matching syntax
  • See MACRO SETTINGS to set preferred browser and other keys

INVOCATION SPEC FORMATS

This macro accepts the invocation spec in four formats:

Format 1 [Url]

The invocation spec is specified as a simple URL. For example:

https://forum.keyboardmaestro.com/latest

Format 2 [Browser:Url]

The invocation spec is specified as a browser identifier (single letter or full name), a colon, and a URL. For example:

a:https://forum.keyboardmaestro.com/latest

Format 3 [YAML]

The invocation spec is specified as YAML. For example:

Browser: Safari
Url: https://forum.keyboardmaestro.com/latest
NewWindowAlways: 0
NewTabAlways: 0
ReloadTab: 0
UrlPattern: --domain # match any tab from the forum 
#TitlePattern: engine\.log # match any tab that includes "Engine.log" in the title
#MatchLogic: or # normally best to let this be inferred, but can be overridden with: none|url-only|title-only|or
ReplaceMatched: 0 # if a pattern match found, replace tab with Url
NewWindowIfNotFound: 0 # to segregate from existing tabs
DryRun: 0 # if set, echo values, but don't open the browser
YAML Notes:
  • All keys are optional; if nothing is specified, Safari will open to the most recently displayed browser tab.
  • Full-line and inline comments are permitted.
  • In YAML, a backslash (\) escapes regex special characters in a pattern. See Regular Expression Patterns for pattern syntax details.

Format 4 [JSON] (deprecated)

The invocation spec is specified as JSON. For example:

{
  "Browser": "Safari",
  "Url": "https://forum.keyboardmaestro.com/latest",
  "NewWindowAlways": 0,
  "NewTabAlways": 0,
  "ReloadTab": 0,
  "UrlPattern": "--domain", # match any tab from the forum 
#  "TitlePattern": "Engine\.log",
#  "MatchLogic": "or",
  "ReplaceMatched": 0,
  "NewWindowIfNotFound": 0,
  "DryRun": 0
}

JSON Notes:

  • All keys are optional; if nothing is specified, Safari will open to the most recently displayed browser tab.
  • Full-line and inline comments are permitted (even though standard JSON does not permit them).
  • In JSON, one or two backslashes (\ or \\) escape regex special characters in a pattern. (Standard JSON requires two.) See Regular Expression Patterns for pattern syntax details.

BROWSER ACTION KEYS

This macro accepts eleven browser action keys. None of the keys are required, and they can appear in any order.

Browser: The browser to use. Valid values: Safari, Orion, Chrome, Brave, Edge, Vivaldi, Arc, Firefox (or single-letter codes: s, o, c, b, e, v, a, f).

Url: The URL to open. Unquoted spaces inside the Url value are automatically converted to %20, e.g., https://example.com/search q=hello worldhttps://example.com/search%20q=hello%20world.

NewWindowAlways: If 1, always open a new window, bypassing all tab matching. This is the highest-precedence override—when enabled, the browser will create a new window regardless of whether a matching tab exists.

NewTabAlways: If 1, always open a new tab in the frontmost window, bypassing all tab matching. This is the second-highest precedence override. If both NewWindowAlways and NewTabAlways are 1, NewWindowAlways takes precedence.

ReloadTab: If 1, reload the tab after selecting it (only applies when a matching tab is found and selected without URL replacement).

UrlPattern: Regular expression pattern† to match against tab URLs. For example: https://forum\.keyboardmaestro\.com.* to match any tab from the Keyboard Maestro forum. See Regular Expression Patterns for pattern syntax and examples. This key also supports a special option, -d (or --domain), which automatically sets UrlPattern to a case-insensitive representation of the Url domain: (?i)^https?://(www\.)?<domain>(?:/.*)?$ e.g., (?i)^https?://(www\.)?forum\.keyboardmaestro\.com(?:/.*)?$

TitlePattern: Regular expression pattern† to match against tab titles. For example: engine\.log to match any tab that includes "Engine.log" in the title. See Regular Expression Patterns for pattern syntax and examples.

†User-specified regex patterns are automatically set to include leading (?i) for case-insensitivity. You can override this by starting the pattern with (?-i). Note also that patterns are not automatically anchored with ^ and $, thus they need to be manually specified when needed. This contrasts with -d (or --domain) that gets translated to a pattern that is anchored to the beginning (^) and end ($): (?i)^https?://(www\.)?<domain>(?:/.*)?$

MatchLogic: Determines how patterns are matched. Valid values:

  • none : Ignore UrlPattern and TitlePattern (inferred when neither UrlPattern nor TitlePattern is provided)
  • url-only : Only match UrlPattern (inferred when only UrlPattern is provided)
  • title-only : Only match TitlePattern (inferred when only TitlePattern is provided)
  • or : Match UrlPattern or TitlePattern (inferred when both patterns are provided)

It is normally best to let this value be inferred, but you can override by setting a value. See Key Inferences and Defaults.

ReplaceMatched: If 1, and a pattern match is found, replace the matched tab's URL with Url. If 0, simply select the matched tab.

NewWindowIfNotFound: If 1, open a new browser window when no matching tab is found (useful to segregate from existing tabs). If 0, open a new tab in the existing frontmost window.

DryRun: If 1, process the invocation spec and echo the resolved browser action keys without actually opening any browser tabs. This is useful for debugging and inspecting how keys are resolved, inferred, and merged with preferences—see Key Inferences and Defaults. If 0, execute normally.

Key Precedence

The browser action key values are resolved in the following order, from highest to lowest precedence:

  1. Caller’s invocation spec — Key values you explicitly provide for the current macro invocation.
  2. Macro variable local_Preferences — Key values applied when not supplied in the invocation spec. See MACRO SETTINGS.
  3. Inferred or internal defaults (mutually exclusive; applied only when neither of the above provides a value)
    • Inferred values — Determined automatically by the macro based on other key values.
    • Internal defaults — Hard‑coded fallback values used as a last resort.

Key Inferences and Defaults

Key Inferred Default
Browser Safari
Url
NewWindowAlways 0
NewTabAlways 0
ReloadTab 0
UrlPattern
TitlePattern
MatchLogic yes
ReplaceMatched 0
NewWindowIfNotFound 0
DryRun 0

†Based on UrlPattern and TitlePattern, the macro infers MatchLogic. Although rarely required, override by explicitly setting: 1) the invocation spec, or 2) the macro variable local_Preferences (see MACRO SETTINGS).

Regular Expression Patterns

The UrlPattern and TitlePattern keys accept regular expressions for flexible tab matching. These patterns use ICU (International Components for Unicode) regex syntax via macOS's NSRegularExpression.

Common RegEx Patterns

Pattern Description Example Match
.* Match any characters (zero or more) (matches anything)
.+ Match any characters (one or more) (matches non-empty text)
https://example\.com Match literal URL (note escaped period) https://example.com
https://example\.com.* Match URL and any path https://example.com/page
[0-9]+ Match one or more digits 12345
(Forum|Discussion) Match either word Forum or Discussion
^https:// Match URLs starting with "https://" https://example.com
Latest.*Topics Match "Latest" followed by "Topics" Latest 25 Topics

Pattern Matching Behavior

  • Patterns (UrlPattern or TitlePattern) match substrings of the page URL or page Title. That is, patterns are not automatically anchored with ^ and $, thus you need to include them when needed.
  • Patterns are automatically set to include leading (?i) for case-insensitivity. You can override this by starting the pattern with (?-i).

Escaping Notes

  • YAML format: Single backslash (\) to escape regex special characters
    • Example: UrlPattern: https://sub\.example\.com.*
  • JSON format: Double or single backslash (\\ or \) to escape regex special characters
    • Example: UrlPattern": "https://sub\\.example\.com.*

COMMENTS

The invocation spec supports comments.

  • Format 1 [Url]: Allows inline comments only
https://example.com  # Opens in default browser
  • Format 2 [Browser:Url]: Allows inline comments only
a:https://example.com  # Opens in Arc
  • Format 3 [YAML]: Allows full-line and inline comments
# Configuration for production site
Browser: Safari  # Primary browser
Url: https://example.com  # Main URL
  • Format 4 [JSON]: Allows both full-line and inline comments
{
# Configuration for production site
  "Browser": "Safari",  # Primary browser
  "Url": "https://example.com"  # Main URL
}

Quoted Values

When a value is quoted, any # inside the quotes is preserved as part of the value, not treated as a comment:

Url: "https://example.com#page"  # The #page is part of the URL
TitlePattern: 'Issue #123'  # The #123 is part of the pattern


FIREFOX LIMITATIONS

Due to Firefox’s extremely limited AppleScript dictionary, the macro will always open the URL in a new tab, even when a matching tab is already present. The NewWindowAlways key will attempt to open a new window; while this behavior is generally reliable, there may be occasional failures depending on Firefox configuration and system responsiveness.

Due to these limitations, the only keys relevant to Firefox are:

Browser: Firefox
Url: https://forum.keyboardmaestro.com/latest
NewWindowAlways: 0
DryRun: 0

MACRO SETTINGS

local_Preferences: Optional YAML-formatted values for any of the browser action keys. When the macro is downloaded and installed, the values are:

Browser: Safari
NewWindowAlways: 0
NewTabAlways: 0
ReloadTab: 0
ReplaceMatched: 0
NewWindowIfNotFound: 0
DryRun: 0

You can change the values with a macro variable or override them using the invocation spec. As with Format 3 [YAML] of the invocation spec, comments are permitted—see COMMENTS.


INPUT PARSING & NORMALIZATION

The macro is designed to be flexible when interpreting the invocation spec, accommodating a range of input conventions and common formatting inconsistencies:

  • Smart quotes — Converts smart quotes to straight quotes in YAML and JSON.
  • Boolean values — Accepts 1/0, true/false, yes/no, t/f, and y/n in YAML and JSON.
  • Case-insensitive input — Treats key names and values as case-insensitive in both YAML and JSON.
  • Lenient JSON parsing — Handles imperfect JSON gracefully, including single backslashes in regular‑expression patterns.

BACKWARD COMPATIBILITY

Macros that called Version 4.0 of this macro will continue to function; however,

  1. Key ReplaceMatchedUrl is no longer recognized; ReplaceMatched should now be used.

  2. Format 4 [JSON] is deprecated but remains fully supported (notwithstanding removal of ReplaceMatchedUrl), but Format 3 [YAML] is preferred due to its simpler syntax and improved readability.


IMPLEMENTATION OVERVIEW

( expand / collapse )

This macro uses a three-stage architecture that separates input processing from browser automation.

Stage 1: Process the inputs (Javascript)

This layer handles all input parsing, validation, and configuration resolution:

  • Format Detection: Automatically identifies whether the invocation spec is a simple URL, browser:URL, YAML, or JSON.
  • Multi-Source Merging: Combines the invocation spec (from %TriggerValue%) with user preferences (from local_Preferences), with invocation spec values taking precedence.
  • Normalization: Removes comments, converts browser identifiers to full names, normalizes boolean values, and handles smart quote corrections.
  • Pattern Inference: Determines MatchLogic value based on provided pattern keys.
  • Output: Produces the resolved browser action (YAML configuration) that is passed to Stage 2.

Stage 2: Convert normalized YAML to local variables (Javascript)

The individual key values are extracted from the resolved browser action. Each is set to a macro local variable. These variables are passed to Stage 3.

Stage 3: Complete requested browser task (AppleScript)

The AppleScript layer performs the actual browser automation:

  • Tab Searching: With the exception of Firefox, efficiently scans open windows and tabs to locate matches using the browser's native AppleScript capabilities.
  • Action Execution: With the exception of Firefox, based on search results and configuration, selects existing tabs, reloads pages, replaces URLs, or opens new tabs/windows as specified.
  • Error Handling: Manages browser-specific limitations (particularly Firefox) and provides appropriate fallback behavior.

This three-stage architecture allows the macro to efficiently support multiple input formats and browsers with differing AppleScript dictionaries.


ADDING OTHER BROWSERS

You can easily modify this macro to accommodate any browser that includes the AppleScript Safari Suite or Chromium Suite. For other browsers with unique AppleScript implementation (e.g., Arc), it would be more difficult, but possible. For more information refer to the Execute an AppleScript actions within this macro.


ACKNOWLEDGEMENT

This macro was inspired by Open or Refresh a URL in a Tab (Sub-Macro) by @DanThomas. Select or Open a New Browser Tab includes some overlapping features.


TESTED WITH

• Keyboard Maestro 11.0.4
• Tahoe 26.2 (25C56)/MacBookPro18,2


VERSION HISTORY

( expand / collapse )

5.0

  • Changed the macro name from Activate, Reload, or Open Browser Tab to Select or Open a New Browser Tab.

  • Browser Additions:

    • Added full support for the Orion browser.
    • Added partial support for the Firefox browser. (Its AppleScript dictionary is extremely limited, so macro interaction with Firefox is a subset of other supported browsers.)
  • Input Format Enhancements:

    • Made Format 3 [YAML] the recommended structured input method due to its simpler syntax and improved readability.
    • Added support for both full‑line and inline comments.
  • Pattern Matching Enhancements:

    • Added webpage title–based matching via the new TitlePattern key, enabling regular‑expression matching against tab titles.
    • Added automatic inference of match logic based on which patterns are provided, with optional explicit override via the MatchLogic key:
      • none — ignore both URL and title patterns (inferred when neither UrlPattern nor TitlePattern is provided)
      • url-only — match URL pattern only (inferred when only UrlPattern is provided)
      • title-only — match title pattern only (inferred when only TitlePattern is provided)
      • or — match either URL or title pattern (inferred when both patterns are provided)
  • New/Enhanced Browser Action Keys:

    • NewWindowAlways: If 1, always open a new window, bypassing all tab matching. This is the highest-precedence override—when enabled, the browser will create a new window regardless of whether a matching tab exists.
    • NewTabAlways — If 1, always open a new tab in the frontmost window, bypassing all tab matching. This is the second-highest precedence override. If both NewWindowAlways and NewTabAlways are 1, NewWindowAlways takes precedence.
    • UrlPattern — This key also now supports a special option, -d (or --domain), which automatically sets UrlPattern to a case-insensitive representation of the Url domain: (?i)^https?://(www\.)?<domain>(?:/.*)?$ e.g., (?i)^https?://(www\.)?forum\.keyboardmaestro\.com(?:/.*)?$
    • TitlePattern — Regular expression pattern to match against tab titles. For example: .*Engine\.log.* to match any tab that includes "Engine.log" in the title. See Regular Expression Patterns for pattern syntax and examples.
    • MatchLogic — Determines how patterns are matched. Valid values: none, url-only, title-only, or
    • ReplaceMatched — (This key replaces ReplaceMatchedUrl.) If 1 and a pattern match is found, replace the matched tab's URL with Url. If 0, simply select the matched tab.
    • DryRun — If 1, process the invocation spec and echo the resolved browser action keys without actually opening any browser tabs. This is useful for debugging and inspecting how keys are resolved, inferred, and merged with preferences—see Key Inferences and Defaults. If 0, execute normally.
  • Settings / Preferences Architecture:

    • Consolidated preferences into a single YAML‑formatted variable: local_Preferences.
  • Usability Enhancements:

    • Smart quotes — Converts smart quotes to straight quotes in YAML and JSON.
    • Boolean values — Accepts 1/0, true/false, yes/no, t/f, and y/n in YAML and JSON.
    • Case-insensitive input — Treats key names and values as case-insensitive in both YAML and JSON.
    • Lenient JSON parsing — Handles imperfect JSON gracefully, including single backslashes in regular‑expression patterns.
  • Macro Design Improvement—Introduced a three‑stage processing architecture:

    • Stage 1 — Input processor: format detection, normalization, and inference
    • Stage 2 — Normalized YAML (from Stage 1) mapped to macro local variables
    • Stage 3 — Browser‑specific AppleScript execution
  • Backward Compatibility : Macros that called Version 4.0 of this macro will continue to function; however:

    • Key ReplaceMatchedUrl is no longer recognized; ReplaceMatched should now be used.
    • Format 4 [JSON] is deprecated yet remains fully supported—aside from the removal of ReplaceMatchedUrl—while Format 3 [YAML] is now preferred for its simpler syntax and improved readability.
  • Documentation & Testing:

    • Expanded documentation significantly, including new Quick Start and Implementation Overview sections.
    • Added the DryRun key for testing configurations before browser interaction.

UPGRADE AND INSTALLATION INSTRUCTIONS

Upgrading From: Activate, Reload, or Open Browser Tab

If you have used a previous version of this macro†, then delete it before installing the new version. If the old version is not first deleted, then existing calling macros will no longer function as expected.

†If you are not sure if you have installed an older version, open the Keyboard Maestro editor, select all macros, and then search for F993DABB-8E10-41C1-9CA7-97CA74E6F9F0. That should identify the old version of this macro and all calling macros.

Installing: Select or Open a New Browser Tab, v5.0

Download: Select or Open a New Browser Tab.kmmacros (179 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 26.2 (25C56)
  • Keyboard Maestro v11.0.4

CALLING MACRO TEMPLATES

1. Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 1 [Url]

Download: Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 1 [Url].kmmacros (4.3 KB)

Macro-Image


2. Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 2 [Browser:Url]

Download: Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 2 [Browser-Url].kmmacros (4.4 KB)

Macro-Image


3. Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 3 [YAML]

Download: Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 3 [YAML].kmmacros (5.9 KB)

Macro-Image


4. Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 4 [JSON]

Download: Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 4 [JSON].kmmacros (6.1 KB)

Macro-Image


5. Select or Open a New Browser Tab 𝘤𝘢𝘭𝘭𝘦𝘳—Format 4 [JSON] via AppleScript

AppleScript ( expand / collapse )
-- Keyboard Maestro macro: Select or Open a New Browser Tab, v5.0+
-- revised: 2026-02-14, Jim Sauer
-- more info: https://forum.keyboardmaestro.com/t/macro-select-or-open-a-browser-tab-v5-0/32808

property theMacroUuid : "C9576AB8-64AB-4EEF-B6E3-572291399828"

property theInvocationSpec : "
	Browser: Safari
	Url: https://forum.keyboardmaestro.com/latest
	NewWindowAlways: 0
	NewTabAlways: 0
	ReloadTab: 0
	UrlPattern: --domain
	#TitlePattern: 
	#MatchLogic: or 
	ReplaceMatched: 0 
	NewWindowIfNotFound: 0 
	DryRun: 0 
"

tell application "Keyboard Maestro Engine"
	do script theMacroUuid with parameter theInvocationSpec
end tell

5 Likes

Hello Jim (@_jims)

You’ve done great work on this one - thanks for this Macro.

Here are some thoughts on adding more features …

  • the change of the NewWindowIfNotFound Key to a string based one instead of integer based with a new Name NewWindowOrTabIfNotFound with the options Tab | Window | Private Window

  • an additional Key ReopenInOtherBrowserIfFound supporting all browsers with closing tab in current browser before opening in the target one

  • an additional Key ReopenInPrivateWindow with closing current Tab beforehand

  • adding Orion Browser and Vivaldi and maybe Arc (if it has AppleScript support) to the supported browsers list

I hope to see these enhancements in the next Version for this macro because I think they‘ll make it even more powerful in versatility.

Greetings from Germany

Tobias

1 Like

Hi, @Nr.5-need_input. Thanks for the positive comment. Glad you like the macro.

Thanks for your suggestions. Unfortunately, at least at this time, I'll only be able to implement one of your suggestions. More below...

If I'm interpreting the above correctly, you are suggesting features that would require the macro to check the tabs for all open browsers. This adds a great deal of complication that would undoubtedly decrease performance. For me, this added functionality would not be worth that cost.

With that said, you are more than welcome to create a fork of the macro that would include this enhancement.

The macro can be easily adapted to add browsers that:

  1. support AppleScript, and

  2. include the Safari suite or the Chromium Suite. (Yes, the former is oddly lowercase suite.)

Of the three browsers suggested, only Vivaldi qualifies. In the next version of the macro, I'll add support for it.

I've been experimenting with Arc and find it very intriguing. Since the creators tout "Arc is the Chrome Replacement" I was surprised and disappointed that it did not include the Chromium Suite. We can hope that it will be added later.

I've updated the OP with Version 2.0 of Activate, Reload, or Open Browser Tab:

  • Added support for the Vivaldi browser which includes the AppleScript Chromium Suite.

  • Added an error message if the "Browser" is improperly specified.

  • When changing JSON in a Set Variable to Text action, the KM Editor sometimes automatically converts dumb double quotes to smart double quotes. This can easily go undetected by a user. Thus, this macro now converts all smart double quotes to dumb double quotes.

  • In this header comment, "UrlPattern" is now shown as "https://forum\\.keyboardmaestro\\.com.\*" with the dots properly escaped with two backslashes (\\.) because two backslashes are required in text within JSON.

  • The Keyboard Maestro Engine converts \\ to \ in text that is passed using With Parameter within the Execute a Macro action. Thus, this macro converts all \ to \\ to add back the second \ so that the JSON remains valid within this macro.

  • BUG FIX: When "ReplaceMatchedUrl" = 1 and "ReloadTab" = 0, the webpage will no longer be refreshed when the browser tab URL exactly matches "Url".

1 Like

Hello Jim

First of all - thanks for Vivaldi support !!

No, I’m sorry to say that - you’re interpreting that wrong …

The Key change from NewWindowIfNotFound to NewWindowOrTabIfNotFound with the options Tab | Window | Private Window I suggested is to make it more clear to the user what is used for the scope of searching - it only adds Private windows to the Browser defined - not to all Browsers. I’ve thought about requesting this but I didn’t.

The Key ReopenInPrivateWindow was requested to complement the first Key to open the matching URL in the Private Window if it is set to 1 and closing the tab in the normal window when found in a Normal and a Private window or otherwise. Maybe therefore I would recommend to use ReopenInPrivateWindowIfFound for a better understanding.

The Key ReopenInOtherBrowserIfFound supporting all browsers with closing tab in current browser before opening in the target one - it is again only thought for the defined Browser in the use of the search scope … not all supported browsers. The support for all Browsers in the list is just for Moving to one of them like so:

  • Tab is in normal window of Safari and moves to Vivaldi with closing in Safari beforehand.

  • Tab is in Private window of Chrome and moves to a Private window in Edge with closing the tab in Chrome’s Private window beforehand.

No search for duplicates in the target Browser.

I hope my request makes more sense to you now… As I requested those features yesterday I was in a hurry … I am trying getting better in asking for features…

While my English is still quite good after nearly 20 years being out of school - it’s still not German - the language I am speaking and writing in for 70% of my day - every day

Greetings from Germany

Tobias

1 Like

I've become a big fan of Arc. It has greatly changed (for the better) my workflow when interacting with the web. It takes a bit getting used to but I love it. As you noted @_jims, it is missing support for features found in other Chromium browsers. I have not had luck in getting javascript to execute on a specific tab in Arc. I've tried to adapt KBM examples in the forum that execute javascript on a specific tab but have not had any success.

Hopefully Arc will add full Chromium someday.

1 Like

Hello,
I just put put up a question for @ccstone responding to his comment where he addressed the same use case. I am trying to figure out a way to do this in brave. That original post seems to be 3 yrs old. Realised you have a post for the same use case that was uploaded recently. Glad to have bumped into it.

I tried your macro with caller example 1 because I need to be able to edit target URL easily. Other caller examples sound like I'll have to edit the URLs at multiple places and inside a code.
I am using Brave.
I had the default URL (Keyboard Maestro Discourse) in the caller. I had the same URL open in Brave. But tab with the URL was not active. Some other tab was active.

When i ran the macro, it gives either of the two outcomes.

  1. It opens the URL in safari (Safari app was not open)
  2. It opens a new tab with the URL in Brave (A tab with the URL was already open in Brave. Just not active.)

How do we resolve this?

What I am looking for:
I need to open a URL. If the URL is already open in some tab of brave browser, the tab with that URL should become active and get the brave browser in the front.
I also use Microsoft edge beta, Google Chrome and Google Chrome beta frequently. If you have a solution for these browsers as well, that would be wonderful.
At a time, I'd be only focused on only one browser for a given URL. (I don't have a use case where I have to check all the browsers with a tab with given URL),

Hi, @fluid_eye. Since Safari is the default browser, you need to use Mode 2 and specify Brave as the Browser. Here's an example:

Download: Activate- Reload- or Open Browser Tab (Caller–Example 2-@fuild_eye).kmmacros (4.7 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 13.4.1 (22F770820d)
  • Keyboard Maestro v10.2

Change the Browser to Edge and Chrome, respectively. Browsers supported are listed in the OP and in the macro header comment.

1 Like

Thanks it works perfect.

I am getting this error msg though. Does this error show by default?

Screenshot 2023-09-06 at 10.03.37

This error occurs only when a tab with given URL already exists.

I also just realised, it turns the focus towards the tab if it contains the URL but macro doesn't execute further actions.
For example, if my macro includes 'insert text' action when it lands on the tab with the URL, it lands on the tab (because it exists with the URL), shows the error and doesn't do the action of text insertion.

Also, I just realised, the macro works for some URLs and not others.
URLs for which it works:

URLs for which it doesn't work:
https://www.google.co.uk/search?q=facebook

When I say 'it does not work', I mean, it doesn't detect the tab with the URL. Instead of focusing on the tab, it creates new tab with the URL. (I only checked this with Brave browser)

Hi, @fluid_eye. Thanks for bringing this issue to my attention; it will be addressed in Version 3.0.

1 Like

I've updated the OP with Version 3.0 of Activate, Reload, or Open Browser Tab:

  • Added an error message if the calling macro uses Mode 2 (JSON), but the "Url" is not specified or the JSON includes a syntax error.

  • Improved the error message if this macro is run directly or the Execute a Macro action does not include a With Parameter value.

  • BUG FIX: When "UrlPattern" is not specified, the macro sets it to "Url". It now properly escapes all special regex characters when setting "UrlPattern".

1 Like

I've updated the OP with Version 3.1 of Activate, Reload, or Open Browser Tab:

  • In browser AppleScripts, changed references to window 1 to front window. The window 1 reference sometimes caused an error for some users.

  • BUG FIX: The embedded browser AppleScripts scan the open tabs in each window. While searching for a match with the specified "Url", the scripts remove a trailing slash in each tab URL. The macro now similarly removes a trailing slash from the specified "Url".

Thanks to @fluid_eye for reporting these issues!

1 Like

Just to educate me @_jims, Arc Browser is advertised as being based on Chromium. I gather that Chromium Suite is something additional? There is an Applescript dictionary but my attempts at converting scripts from other browsers have pretty much failed. It would really be nice to have this macro (and others) working for Arc.

Hi, @cyoungers. Correct, it's additional and since The Browser Company is developing Arc for Windows, they have their hands full.

Before I knew of their Windows effort, I did reach out to TBC to ask about the Chromium Suite, but thus far have not heard back. With that said, each time I update Arc, I do use Script Debugger to search. But as of Arc, Version 1.8.1 (41651), no dice. :frowning:

In contrast, here's Brave.

1 Like

Hello jim, I was wondering if it is possible for you to add support for 'Google Chrome beta'. I have no idea how difficult/easy it is given that the macro already supports chrome but it was worth asking once to you as Google Chrome beta is the browser I use frequently.

Hi, @fluid_eye. I'm not sure. I've never used the beta. Does the beta appear differently otherwise to Keyboard Maestro (e.g., activating the app, etc.)?

If it appears the same, then Activate, Reload, or Open Browser Tab should work it in the same manner as any other version of Chrome.

If it's different, then please share any other macros that you have that work with it. That might give me some clues. (I really don't want to download the beta.)


I'm traveling for a week, thus I probably won't be able to help much for several days.

Thanks for your prompt response Jim.

I don't think so. At the same time, I never really used a macro on beta.

Let me try replacing the text string 'Google Chrome' with 'Google Chrome Beta' everywhere (in subroutine, in caller, in apple script etc). Am I thinking in the right direction?

I had tried replacing 'Safari' with 'Google Chrome Beta' in only the apple script action and it gave me syntax error. I don't know any programming language.

If it is really difficult, seems like the option that i'd resort to is using 'search tabs' option from the menu.
I also tried using 'if/then' action to perform action based on window titles


but KM somehow do not check all open windows of 'Google Chrome beta' (I tried same action for safari. KM doesn't detect safari windows either.)

That definitely wouldn’t work because Chrome and Safari have different AppleScript dictionaries.

That might work, but I have no experience with the beta.


Sorry I’m away from my computer for
10 days so I really can’t help much until then.

1 Like

I've updated the OP with Version 3.2 of Activate, Reload, or Open Browser Tab:

  • BUG FIX: The Brave Browser AppleScript had an extraneous character at the end that prevented proper execution.