I want to open DevTools (Console) in Google Chrome but only if it is not already open. The window may already be open and be docked or floating. Is there a way to detect if the console is open and whether it is docked or not?
The aim is to do this:
- Open the console to show results (by sending keystroke CMD + Alt + J), but only if the console is not already open.
If the window is floating then Keyboard Maestro can detect it by name.
window.outerHeight - window.innerHeight
And if you have the panel on the side of the window instead of in-line vertically you'll have to work with width instead of height.
Ah, that is a good plan. I thought that the floating window could be detected, but not when docked (and I normally have it docked). So a JS solution looks to be the way forward. I did wonder whether one of the dev tools controls might be detected as a button in order to ascertain whether the panel is showing. Thanks
I looked to see if that could be done with AppleScript UI-Scripting, and it can't – so I don't think Keyboard Maestro's button-detector will work either.
If you still need the Chrome inspector, (forgive me if this is too obvious), you’ve considered using a “found screen” image condition to look for a part of the inspector to be open?
Hi Joel - That's a good point - I certainly could do that. However, the script I am running will be used by other people in a number of browsers/OSs, so the results have to output to the console. As such I do need to verify what others will see, hence wanting to have KM automatically open it after running. But if the results are the same in a KM window as console, then I guess I'm fine to do that
Also, 'found screen' is not too obvious—this is not something I have used before, but I'm glad you mentioned it because the ability to find something based on an image and click it will be VERY useful for another task
The found image tools in KM are a huge help, but since apps and websites update their styling all the time (and even MacOS updates can change the appearance of things and break my macros), I try to find other solutions before relying heavily on the "found image". But for when we have no other choice, it's one of the most powerful features of KM.
I found a way to open Chrome JS Console that works for me consistently.
As you probably found out, the menu item or keyboard shortcut seem to work as a toggle, so you don't know if it's already open or closed.
In case it helps, here is a submacro that you can use in your other macros.
You can use it by passing the url of the page where you want to open the JS Console. For example:
It's simple, but every day there is someone new learning KM that might stumble across these posts and might find something new!
_TEMP-TESTING Macros.kmmacros (4.4 KB)