Macro Set: Toggle Between Browser Tabs

Macro Set: Toggle Between Browser Tabs

DOWNLOAD:

Macro Set -- Toggle Between Browser Tabs.kmmacros (89 KB)

This download contains two macros:

  1. @Browser @Toggle to @Previous @Tab
  2. @Browser Set @Previous and Current @Tab When Win Title Changes

Both were uploaded in a Disabled State.

These macros are based in large part on the great macros written by
@kevin_funderburg. See Select Previously USED Safari Tab (not previous tab)

Primary Changes

The primary changes I made to @kevin_funderburg's macros:

  1. Extended to include both Safari and Chrome Browsers
  2. Added FireFox using a FF extension

###  MACRO #1:   @Browser @Toggle to @Previous @Tab
 
~~~ VER: 2.0    2017-03-29 ~~~


---

### ReleaseNotes

Author.@JMichaelTX

 * Author of Original Macro:  @kevin_funderburg
(see Reference Comment for details)

**PURPOSE:**

* **Toggle Between Browser Tabs**

REQUIRES:

* Companion Macro "@Browser Set @Previous and Current @Tab When Win Title Changes"

HOW TO USE:

1. Open Safari, Chrome, or FireFox Brower
2. Open more than 1 Tab
3. Click on another Tab you want to toggle to
4. Trigger this macro to toggle between the two Tabs
5. At any point, click (or open) on another Tab, and it will now become one of the Tabs to toggle between.

**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 Maco, not me.  😉
.
* Assign a Trigger to this maro.
* Move this macro to a Macro Group that is only Active when you need this Macro.
* Enable this Macro (if needed).
* This is the **Main** Macro of a set of Macros that are required.
* You must also install this Macro:
  * @Browser Set @Previous and Current @Tab When Win Title Changes

TAGS:  

USER SETTINGS:

* Any Action in _magenta color_ is designed to be changed by end-user

ACTION COLOR CODES

* To facilitate the reading, customizing, and maintenance of this macro,
      key Actions are colored as follows:
* GREEN   -- Key Comments designed to highlight main sections of macro
* MAGENTA -- Actions designed to be customized by user
* YELLOW  -- Primary Actions (usually the main purpose of the macro)
* ORANGE  -- Actions that permanently destroy Varibles or Clipboards,
OR IF/THEN and PAUSE Actions

REQUIRES:

1.  Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
2.  El Capitan 10.11.6+
  * It make work with Yosemite, but I make no guarantees.

**USE AT YOUR OWN RISK**

* While I have given this limited testing, and to the best of my knowledge will do no hard, 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.

---

<img src="/uploads/default/original/2X/3/3ec1c8827f57ceeb9fad9a039188b21f6e071336.jpg" width="470" height="910">

###MACRO #2:   @Browser Set @Previous and Current @Tab When Win Title Changes

~~~ VER: 2.0    2017-03-29 ~~~


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Set the KM Variables for Current and Previous Tab when the Window Title (and thus the Tab) Changes

REQUIRES:

  • Companion Macro "@Browser @Toggle to @Previous @Tab"

HOW TO USE:

  • This macro is NEVER to be triggered directly by the user
  • It will be automatically triggered when the Broswer Window Title changes.

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 Maco, not me. :wink:
      .
  • Macro Tirgger: MUST Be "The focused window title changes"
  • Move this macro to a Macro Group that is only Active when any Broswer is Frontmost.
  • Enable this Macro (if needed).

TAGS:

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

ACTION COLOR CODES

  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Varibles or Clipboards,
    OR IF/THEN and PAUSE Actions

REQUIRES:

  1. Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
  2. El Capitan 10.11.6+
  • It make work with Yosemite, but I make no guarantees.

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge will do no hard, 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.

5 Likes

Hi Michael (or anyone else),

Can you please tell me how to make this also work in Microsoft Edge?

Sadly, the OP Jim passed away a while back. Maybe someone else can help, but with a 7 year old macro, I wouldn't hold my breath.

If you're interested in making this work with the Comet browser, here is what I did (with the help of ChatGPT).

What we did

We added Comet browser support by extending both macros:

  1. @Browser Set @Previous and Current @Tab When Win Title Changes Added a Comet case in the “Set Tab Index Based on Browser” switch, with this action:
-- Get the active tab index from Comet and feed it to SPT__TabIndex
try
  tell application "Comet"
    if (count of windows) = 0 then return
    set idx to active tab index of front window
  end tell

  tell application "Keyboard Maestro Engine"
    setvariable "SPT__TabIndex" to (idx as text)
  end tell
end try
  1. This keeps the macro’s normal variable-tracking flow intact (DND__TabCurrent, DND__TabPrevious).
  2. @Browser @Toggle to @Previous @Tab Added a Comet case in the application switch, with this action:
-- Switch Comet to the previously used tab index tracked by the companion macro
try
  tell application "Keyboard Maestro Engine" to set prevIdx to getvariable "DND__TabPrevious"

  if prevIdx is "" then
    -- Seed history if first run: move to a neighbor tab
    tell application "Comet"
      if (count of windows) = 0 then return
      set w to front window
      set i to active tab index of w
      set tabCount to count of tabs of w
      if tabCount < 2 then return
      if i > 1 then
        set active tab index of w to (i - 1)
      else
        set active tab index of w to 2
      end if
    end tell
  else
    tell application "Comet"
      if (count of windows) = 0 then return
      set active tab index of front window to (prevIdx as integer)
    end tell
  end if
end try

Why this was needed

  • Comet doesn’t support KM’s built-in CHROMETABINDEX() or SAFARITABINDEX() functions, but it does expose active tab index via AppleScript (Chromium base).
  • With these scripts, Comet follows the same architecture as Safari/Chrome: the state-tracker macro maintains the “current” and “previous” tab variables, and the hotkey macro toggles to the stored previous tab.

Impact

  • The macros now support Comet seamlessly.
  • This same pattern could extend to other Chromium-based browsers that support active tab index (Brave, Arc, Orion, etc.).

The Comet browser is owned, at least in part, by Jeff Bezos. However I won't say anything inciteful.

It's becoming really rather tiresome how so much is owned by so few.