How to Group Similar Tabs to the Right in Google Chrome with Keyboard Maestro

Building on this macro Toggle between tabs of a specific type, I am now trying to make another macro that allows me to group all the tabs of similar types to the right in google chrome, based on the current tab I am in (e.g. If my current tab is youtube, it will scan through all the tabs and move all the youtube tabs to the right side of the tabs bar)

The macro below I made works like only 30-40% of the time. I'm not sure why or how!?
Group similar tabs - to the right.kmmacros (7.2 KB)

I integrated this macro with a Chrome extension called Rearrange Tabs (https://chromewebstore.google.com/detail/rearrange-tabs/ccnnhhnmpoffieppjjkhdakcoejcpbga)
I set a shortcut (control + command + ↓) in that extension to move the current tab the "right-est" position and it is used within the macro here.

Here's how I structure the macro:
I first set a variable (original_chrome_url) for the current tab's URL which will be used in the last step. Then, using regular expressions, I capture the pattern of the URL from http(s):// up to the first / and store it as another variable (local_theDomain)

Subsequently, it checks the URL of every tab to see if they matches the URL of interest (i.e. local_theDomain). If matched, it will move that matched tab to the "right-est" position (control + command + ↓) and go back to the first tab in the tab bar (command + 1) and continue scanning.

If it doesn't match the URL of interest, it will simply move to the next tab (option + command + →) and continue scanning

The whole process only pauses when it eventually moves back to the original tab that we first started (aka the variable "original_chrome_url")

My question is why did this only work sometimes? (It paused on its own midway quite often) and if there's a more efficient way to go about this?

Try adding a brief pause between the two keyboard shortcut actions—it might be a timing issue.

-rob.

1 Like

I added a 0.1s pause and no more issues now! :slightly_smiling_face: Thx!

I'm not sure but I have two and a half ideas.

A few days ago someone had a similar issue and I told them to place a Semaphore Lock action at the top of the macro, and that fixed the problem. The reason it fixed the problem is that two copies of the macro were running at the same time, and a Semaphore Lock action would solve that problem. In your case, running a second time before the first one has finished could cause the macro to fail.

A second idea, which can potentially help you out, is to turn on the Debugger and you will see if two copies of the macro are ever running at the same time. If so, you need to fix that. Your macro is not designed to support two simultaneous copies running at the same time.

A third idea also involves the Debugger. That's because there's a very real chance that the reason it isn't working is that it isn't triggering. You will be able to see that in the Debugger window if you press the hotkey and nothing happens. Using the Debugger is easier than checking the KM Engine log because you can see the results instantly when you trigger the macro.

Griffman is suggesting that you insert a pause. That's also a good idea, but I stand by my ideas as possibilities. EDIT: Okay, Griffman was right, if you say that fixed it.

1 Like

I have never even heard of semaphore lock before and I've never used the debugger. Looks like I have some more research to do! Thank you folks for teaching me stuff with KM! learnt a lot lately!

1 Like