Make google chrome automatically open up a new window whenever i only have only 2 chrome windows open

Hi

I want to make google chrome automatically open up a new, fresh window whenever i only have only 2 chrome windows open. Is this possible to do with Keyboard Maestro? If so, how?

This should work:

MACRO:   Open New Window IF Win Count = 2 [Example]

~~~ VER: 1.0    2018-04-03 ~~~

DOWNLOAD:

Open New Window IF Win Count = 2 [Example].kmmacros (3.0 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


image

2 Likes

Thank you!

I just downloaded it and enabled it, but its not working yet. The set variable part seems to be recognizing the amount of open windows, but it always says false for the if/then action. Here's a pic taken while i have 2 windows open in chrome:

image

What should i do?

Did you try actually running the macro?

The reason the IF/THEN shows false in the KM Editor is because the variable “Local__NumWin” has NOT been set yet.

1 Like

No i don’t think that i did. What do you mean by the variable not being set yet? I’ve never used variable action before- how do i set it?

I just tried setting the macro trigger to “If Google Chrome is active” (and repeating every 1 second) and it is now working perfectly. The only thing that i am wondering is if checking to see if chrome is running every second might consume alot of system resources? Is this a good way to do it or is there a better way to set or trigger it?

The variable is set when the macro actually runs. When you view it in the KM Editor, it has NOT yet run.

The macro I gave you is just an example of the method. You need to adapt it to your actual use case, which I don’t understand.

Perhaps if you list your workflow steps in detail to show exact when and how you want a new Chrome window it would help.

My use case: I use an extension for chrome called tabs outliner in google chrome that allows me to ‘save but close’ windows of tabs. When i hit command N to open new window when there are no other open, blank Chrome windows - it re-opens the last ‘saved but closed’ window and appends a new tab to it. i want to open a new window automatically so that this does not happen - so i always have a fresh window instead.

Ok, I think its setting the variable because its running now when i set the trigger as i explained here.

Still wondering about those questions, would appreciate if you could answer.

In that case just create a macro (in a macro group only for Chrome) that uses the ⌘N as a trigger. It can then check for the number of windows (and/or other criteria) that Chrome as open, and either open a new window or a new tab.

I think @peternlewis is the best person to answer this. However, personally I would not use such a frequent trigger unless there was no other solution available.

1 Like

Generally I don’t recommend frequent time triggered macros except as a last resort. For one thing, a macro triggering will cancel any “once” or conflict palette choices or the like, and so frequent timed trigger macros will likely cause problems with that.

1 Like

Thanks again.

Ok that makes sense, i just tried this but realized this issue happens more than just when i hit command N to open a new window- it also happens when i use launchbar or spotlight to search the internet.

I figured that i can get around this by triggering the macro so that it checks the amount of windows when i close a tab or window in chrome (command W to close tab or shift command W to close window). Made the following macro but its working for some reason that i havent been able to figure out. Do you know what i'm doing wrong here?

image

image

I don’t think I understand your overall strategy with using Chrome. I like to keep things simple, so if it were me here’s what I’d do:

  1. Set Chrome to default opening new URLs in a new Tab.
  2. When that happens, if you want it in a new window, then just have a macro that:
    • Gets the current URL
    • Closes that Tab
    • Opens the URL in a new Window.

I did just think of one idea: You can have a trigger based on when the window title changes. So that macro could check your number of windows, and move the URL to a new window.

2 Likes

Hey Guys,

Perhaps I'm missing something, but this looks like a job for the Focused Window trigger.

image

-Chris

Yep, exactly what I was suggesting here:

1 Like