Modifying Palette While Open?

I need something like a palette that stays up indefinitely until the closed by the user whose entries can be added to or removed by a macro while the palette remains open? I know it’s possible in KM because that’s what the palette put up by Activate Clipboard History Switcher does (it at least reorders the item, I don’t know that it either adds or removes them with actions such as Delete Clipboard 2). But maybe that’s a special case.

Ideally I want a small floating menu of items the user can select (preferably as a button, rather than a GUI menu item, as in the Clipboard History Switcher), with other macros adding or removing items, with the change seen instantly. I’ll call this a dynamic floating menu, for lack of a better or more erudite term. (There are probably GUI frameworks that define something like this, but though I’ve used many at the moment I can’t think of any that do.)

Acceptable solutions include a non-floating palette, a menu trigger that brings up The items (without the need for a palette) where those items are dynamically added and removed – activated and deactivated I guess, or anything else that produces in effect a dynamically configurable menu. I considered the menu bar script —uh, whatever that is — but making files in a folder go away and appear is too heaving handed. The entries should each just be a name and a value.

It is also not entirely necessary that the dynamic menu be visible at all time. The simplest solution might be an activate a palette for one action when a keystroke is pressed, then rely on the corresponding collection of actions to populate the menu, leaving out those that are disabled (by another macro).

However this is done, ultimately I would want the user to be able to press + to add an item and to remove, but some less elegant interface is acceptable — selecting an existing item and pressing DEL to delete, and filling in an Other.

I'm not sure this is really doable, but someone else may have other ideas.

You said some things about menus, but I'm not sure I understood what you were saying. Let me tell you what I use, and perhaps it will be helpful.

I use BitBar to show some menus - don't quit reading yet! I have only one plugin in the BitBar folder, and I don't change it when I change the menu. All the plugin does is retrieve the actual menu from a Keyboard Maestro variable.

So in order to change the menu, all I have to do is change the KM variable. If I want the changes to show immediately, I manually tell BitBar to refresh itself. But I could setup the plugin to refresh itself every 5 seconds if I really cared.

Here's the icon without the timer running:

Here's the drop-down, while the timer is active:

And here's how I build the menu (part of it, anyway):

If you want more details, I'd be happy to supply them. I'll understand if this won't serve your needs, but I thought I'd mention it.

Your discussion made me realize that although I was imagining a permanently visible menu, it would be quite alright — and maybe better — to have the menu popup on a keystroke. See Reveal Safari Windows. Something like that macro’s popup would be sufficient, as long as I could dynamically add to and remove from the palette it presents. I don’t really need it to be permanently visible.

By the way, I think I am going to change that macro. The way it works is that if it asked for a string with a slash, it looks at URLs, otherwise it looks at window titles. I have run into enough windows with content titles that don’t include the name of the site or top-level starting point, where I am starting to think i should check URLs even if the string doesn’t have one. (An example: the window title “Document” in the documentation pages for a NoSQL database that doesn’t include the name of the database in the title)

Always good to kick around —and qualify — design ideas before diving down an implementation hole.:slight_smile:

For simple cases, you can use a Macro Group palette and enable/disable macros.

I presume your usage goes beyond that.

The other option would be a Custom HTML Prompt which allows you to do pretty much whatever you want.

Other than that you will need to use some other GUI generation tool.

Are there any issues with leaving a Custom HTML Prompt open for an extended period of time? Other than the icon flashing constantly, I mean. :slight_smile:

Nope. I’ll see if I can add an async mode so it can stay open without the macro having to continue running.

1 Like

Oooh, that would be cool!

There isn’t any way to use JXA in a Custom HTML Prompt, is there? Because without it, using a Custom HTML Prompt as a Palette of some sort isn’t as useful as it could be. True, we could probably use KM’s URL scheme to launch macros (we could, from a Custom HTML Prompt, right?), but other than that, it would be pretty limited.

You can’t use JXA, no, but you can get and set variables, process tokens, calculate function results, and trigger macros. So you can perform quite a lot, and your JXA could be in a macro that you trigger.

Sometimes I amaze myself with how easily I forget things. While thinking about the fact you can’t run JXA from a Custom HTML Prompt, I totally forgot about being able to set variables using the other method you provide inside the HTML prompt, even though I’m working on code right now that does just that!

Sheesh. Getting old sucks.


As I realized during the initial discussion a popup menu would work too. Both would be cool — I like the async idea, which addresses my original formulation, but would also find the popup idea useful. The popup approach is shown in the macro I mentioned above. I want suggestions about how I could construct that list dynamically — each time it is popped up, really. A representative, but not meaningful example, would be a popup menu of all the tabs of the front Safari window.

In my OP I was hovering around the idea of turning macros on and off, or even adding and deleting them, so that they would appear in the dynamic menu. I’ve come to realize that that is just silly. All of my use cases for this kind of menu would involve executing the same macro, with input being the menu choice. (Not that I could think of how to do that off the top of my head.)

So I think this breaks down to:

  • A menu of choices
  • When the user selects an entry, one macro is called with the selection as an argument
  • It is necessary to add and remove terms from the menu dynamically.

Then, the presentation choice is either:

  • a permanent palette located where the user drags it
  • a popup menu that is contracted before popup

Although I was originally envisioning a static menu, I think a popup would be the better implementation for my use cases. It also makes populating the menu far easier.