Let's say I want to dynamically assign a window a number (or an alias) to be able to later activate it very quickly.
For example, say that I manually activate a Chrome Window that contains several Amazon searches, and I want to assign it the number 1 , so that I can later activate it with a keyboard shortcut e.g. option+1. Similarly I may have another Chrome window holding a different set of tabs (e.g. StackOverflow tabs), and assign it the number 2 , so that I can later activate it by doing option+2 ... and so on.
A variant of the above would be using aliases (strings) that would autocomplete in a quick prompt on the screen instead of just numbers. For example, I could open a Chrome window, give it an alias (e.g. "foo"), activate a second window and give it an alias (e.g. "bar"), and then later, with a simple shortcut that prompts an autocomplete form, I could just type "foo" or "bar" enter, and it would immediately activate the corresponding window.
Can I do this with Keyboard Maestro alone? If not, I'd imagine I could do it with a combination of Keyboard maestro + Applescript, but how?
Thanks @hello - Yes, I knew I could create them manually in KBM ahead of time. I truly meant dynamically in my post, sorry if that wasn't fully clear. As an example (motivating) application (of many): I may have several Chrome Windows open, each with its own set of tabs, and I want to give them different aliases (or numbers), depending on their content, to be able to activate them later quickly. Again, this is just an example.
I think you might want to take a look at Hook, but I don't use it and can't really say it's in the ballpark of what you want.
You can create Keyboard Maestro macros with AppleScript, so it's easy enough to assign an activate-app ⇢ activate window sequence to a macro and give it a keyboard shortcut.
Here's the basics of how to create such a macro on the fly:
It will take some adapting to fit your use-case though.
The big trick you run into is allowing for changes in your set-up.
For instance – you've assigned a bookmark to a web page in Google Chrome, but then you monkey with that window and change the tab order.
Here is one untested idea that you might use if you are willing to limit the window selection to the current (frontmost) app (Chrome in your example).
This does NOT let you assign a number or name to a window, but allows you to quickly display the list of windows for a given app, and then choose the window to activate by number or Title.
Using the KM Token %WindowName%All%, you can get the current list of windows.
Turn off the "auto-sort" in the Gear menu to show the current order of windows
• Choose the target window by incremental-search of text in the Title
You could add Window# to the list if you want to use either the KM For Each action or a simple AppleScript, JXA script, or Shell Script, BEFORE the Prompt with List Action.
This has the advantage of simplicity that will work with each app, and something that you can probably do quickly. You could also get a list of apps, choose the app, then the window; OR combine App Name with Window Name into one list. Of course that takes more work, and is more complex.
Just to show you an example of what is possible with a lot of work, and a complex JXA script, here's a screen shot of the Prompt with List that I use in one of my macros: