How to switch focus to a window of certain name

I have the following macro I use to open a project quickly in my editor:

21

I want to extend so that if this project is already open, it will switch to it and not call the open action again as that will create a new window with the project.

In order to do this, I think I need to do an if check that will scan through all my active windows and check if anything that has text - web-test inside it.

22

Only problem is I don't know how I can do this. KM doesn't seem to provide a native action for this and I searched around and couldn't find any applescript or JXA to do this.

Would love any help on this. :orange_heart:

Hey @nikivi ,

I've never used VSC, but if the text web-test is in the title of any of its windows, something like this seems like it would work:

image

1 Like

This works indeed. Thank you!

Only thing I am curious about is why do I need to activate the app before triggering the Bring Window action. Without bringing VSCode as active app, bring window doesn't seem to work and I don't get why.

39

Oh never mind I got it. This is what I wanted:

43

KM is amazing.

1 Like

Hey Nikita,

By now you should know that you can drop an application on Apple's Script Editor.app to find out if it is scriptable.

Drop the Keyboard Maestro Editor on it for a demonstration of how it works and looks.

Visual Studio Code definitely is NOT scriptable.

Save yourself some time next time.

-Chris

2 Likes