How to Generate a Pseudo-Palette of Choices That are Not Macros

I'm looking for ideas on how to proceed with an project I'm working on.

What I think is the solution is to generate a display window with a bunch of lines of text, where each line starts with a single character that is the key to select that line. Like a menu, palette, etc. Then when I press the key for the first character on the line, KBM sets a variable, runs a macro, or whatever is needed.

The key issue is that I want the list to be dynamically generated, I don't want it to be "hard coded" like a list of defined macros is. I want to be able to change things in the course of my work and then I want KBM to run a little macro to find out the contents of the list based on what I've done and present the list to me to choose from. I don't want the housekeeping of having to manually go into my macro definitions to update the list before the current situation can be displayed in the menu.

Then, depending on the key I press based on the menu entries, KBM will do the appropriate things.

I think this may have various applications in addition to my current desire.

What I want to do with it now is to help manage all the different Desktops that I use. Right now I have seven Desktops in my laptop monitor and fourteen in my external monitor. I use the Current Key Stats program (free) to assign names to them all which are more mnemonic than the Mac Mission Control names of "Desktop 1" ... "Desktop 21". I have desktop workspaces for Email, Research, Project 1, Project 2, Project 3, Facebook, Money, Health, Music, Movies, etc. Sometimes in working on some internet research or software experimentation, it's useful to to arrange two Desktops side-by-side that I flip back and forth between. So I may temporarily change the name of a Desktop. I have a Logitech mouse with a tilt wheel and there's a setting where tilting the mouse wheel will move me left or right among my Desktops.

One technique I have found really useful is that I can move windows between Desktops by grabbing the window with the mouse, moving it a little, then pressing the hotkey to change windows and the moving window gets moved to the new Desktop. That's really handy. That's what I really want KBM's help with is being able to do all the hotkey-based Desktop selection with only my left hand while I hang onto the widow with the mouse in my right hand.

I got started with connecting KBM to AppleScript to Current Key in this thread: https://forum.keyboardmaestro.com/t/how-to-get-a-currentkey-room-name-mission-control-desktop-from-applescript/21005. Where that just reports the name of the current Desktop (CKS calls them Rooms) using the getactiveroom function, there is also a getassignedrooms function which returns a list of all the current room names, separated by underscores. That's my KBM starting point.

Fortunately, there is a KBM plugin called SPLIT (https://forum.keyboardmaestro.com/t/split-custom-plugin-split-a-string-to-a-km-array/21177) which will create a KBM array given that string and being told that the underscore is the delimiter.

So I want to use SPLIT to generate a list of all the current Desktop names and then have KBM wait for my keyboard input to tell it which item in the list I'm choosing, and then use the CKS AppleScript gotoroom to change Desktops.

The part I'm having trouble outlining is that last part: how to read a single keystroke and set a KBM variable or choose an action based on that.

I can do it with a KBM palette, but to make that work I have to have the CKS names of the various Desktops hard-coded, I cannot change them on the fly, while I'm working on something else. Any time I change a Desktop/Room name I would have to go into the KBM Editor and update that palette.

Anybody want to brainstorm some ideas with me on how to do this?

Thanks.

You can automatically run a macro using the trigger "Display Layout Changed"
https://wiki.keyboardmaestro.com/trigger/Display_Layout_Changed?s[]=display&s[]=layout&s[]=changes

detects when you rearrange monitors or when you add one.


Screens also have their own numbers and/or can be called by their index:
https://wiki.keyboardmaestro.com/function/SCREEN

Thanks @hello, those look useful, but aren't quite on the mark. I'm talking about Mission Control Desktops / Workspaces, not monitors or screens.

I don't think that "Display Layout Changed" will be triggered when I rearrange the order of Desktops since it seems to only be about monitors or monitor arrangement.

And, because I want to be able to rearrange the order of Desktops, changing Desktops by their numbers is less than fully useful.

The thing I'm focussing on trying to figure out is how to have a macro wait for a single keystroke, not wait for F2 but rather wait for one of [ ` 1 2 3 4 5 q w e r t a s d f g z x c v b ] and then do something depending on which keystroke it got.

Any ideas?

I've got five ideas I'm looking at now (and counting):

  • Use the Pause Until macro and having a list of "any of the following are true" that includes all the different key presses that I might use for choices and see if I can automate assigning the CKS Desktop/Workspace/Room names to those keys, based on having the key be the first character of the name.

  • Use KBM Editor Scripting to automatically make a KBM palette out of the list of Desktop names.

  • Somehow use Dictionaries, which I don't understand yet.

  • It looks like I can use Variable Arrays (https://wiki.keyboardmaestro.com/manual/Variables#Variable_Arrays) to parse the list of Desktop names, because that's exactly what I get back from getassignedrooms. I may not need to use the SPLIT plugin.

  • Use Prompt With List. I've trying some versions of this, which appears in general to be a great way to make menus in certain circumstances. However, I cannot find a way to make a menu choice using the keyboard. Even when I type sufficient characters to reduce the choices to one, that is not chosen until I either click on it with the mouse or press the Enter/Return key.

I'm now thinking that my original design was overthinking the problem and making too complex a goal for a first pass. Hence the overly long OP that I imagine no one has read without getting confused.

I've been working on how to generate a menu automatically when I haven't generated the same menu, or at least a short version of it, manually yet.

Problem Solving 101.

Hey August,

The only way to do this exactly the way you want (I think) is to use a Custom HTML Prompt action.

If you have the HTML/JavaScript chops you can go wild.

-Chris

The KM Prompt With List action is very close to that.
The only difference is that you would need to press RETURN (or ENTER) after pressing the key that selects the target line.

The Prompt with List offers several different types in input, including text, Variable, and file. So you can dynamically construct the list and then feed it to the Prompt.

You will save the results of the Prompt with List to a KM Variable, which you can then use in a KM Switch or Case action.

I have only scanned most of your long post, but I think the above covers most of what you want. If not, please feel free to post specific questions.

Thanks Michael.

I've tried Prompt With List and you're right, it's very close.

But the need to click with the mouse or press Return/Enter blows it for my workflow. I want to press hotkeys entirely with my left hand while drag a window with the mouse in my right hand. When I start dragging the window, if I then hotkey to a new Desktop, the window gets taken to the new Desktop along with my view. Since I am regularly moving windows between Desktops, I really need this functionality.

Thanks.