Naming (Or Numbering) and Activating Windows Dynamically

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?

Related question in SuperUser if helpful :slight_smile::

I know @ccstone or @appleianer will appear and post something cool,
so, in the meantime:

don't know if dynamically, but

You can create those macros manually:

  1. Browser

2.- App

gotta say it took me longer to write the post than to create the macros

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.

Hey Amelio,

Can it be done? Yes.

Can it be done robustly? Good question.

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.

I think I would take a different approach.

Save a Bookmark to a Global Variable:

Window Bookmarks ⇢ Save 1.00.kmmacros (6.1 KB)

Retrieve a Bookmarked Window:

Window Bookmarks ⇢ Retrieve 1.00.kmmacros (12 KB)

These work but I haven't spent any time trying to make them bombproof.

I've prefixed each line in the bookmark file with a number for easy access.

If the given window is not found Keyboard Maestro will throw an error notification, but it will still activate the given app.

If the app is not running it will be launched.


ha, that was my first thought, but wanted to avoid adding another app.

with Hook you can run it, and then create a ".hook app"

so then it'd be a matter of
"run app" for any of them

1 Like

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).

  1. 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.
  2. Using the KM Token %WindowName%All%, you can get the current list of windows.
  3. Use the KM Prompt With List action to display the list
    • 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.
  4. Use the KM Manipulate a Window action to bring the chosen window to front.

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: