MACRO: Dialog with Dynamic Popup List v1.1


PURPOSE

This macro demonstrates a Prompt For User Input Dialog Box with the following characteristics:

  • Includes additional descriptive information the first time the macro runs.

  • Dialog box settings are saved to a KM dictionary rather than separate global variables.

  • Contains three elements: Text Entry (New Color), Popup List (Color Selection), and Checkbox (Delete Selection).

    • The Text Entry value can be used to add an item to the Popup List item. Added items are sorted.
    • The Checkbox value can be used to delete an item from the Popup List item.
    • The default Popup List item changes based on the previous macro action.

DIALOG BOX SETTINGS

As mentioned above, the dialog settings are saved to a dictionary. The name is jsDDPL_dict, where js are my initials and DDPL represent the macro name. The structure is as follows:

{
  "ColorSelection": "Blue",
  "DeleteSelection": "0",
  "OtherColors": "Blue\nGreen\nRed",
  "RunStatus": "1"
}

TESTED WITH

  • Keyboard Maestro, v10.0.2
  • Monterey, v12.2/MacBookPro16,1
  • Mojave 10.14.16/Macmini6,2
  • High Sierra 10.13.6/iMac11,1445

VERSION HISTORY

1.0 initial version
1.1 No change to macro functionality. Defined local_DICT and used it rather than hard-codng dictionary name throughout.


DOWNLOAD Macro File:
Dialog with Dynamic Popup List.kmmacros (50 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image

4 Likes

As I was learning about KM Dictionaries there were a couple important points I discovered:


Here's a utility macro I created and used while I was learning about KM dictionaries. It's very basic but includes examples of these dictionary functions:

  • Add/Update a Key
  • View All Keys
  • View Two Specific Keys
  • Delete Dictionary By Setting All Keys to null
  • Delete Dictionary By Setting JSON {} [much simpler method]*

* added after receiving the feedback below from @Zabobon


DOWNLOAD Macro File:
Dictionary Functions-jsDDPL_dict.kmmacros (24 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image

1 Like

Hi @_jims these Macros are great and I think your idea of using Dictionaries to store the default choices is really brilliant. Lots to copy and use here!

And the recommended way is as you are showing, with a For Each Loop and several Actions. I was doing that too, but the other day I stumble across the below by @kvanh

It uses one single Action (the Set Dictionary to JSON Action) to delete the dictionary in one simple step. It means you can clear whole Dictionaries at the end of a Macro as simply as you would delete Variables. And that makes them even easier to use as temporary storage for just one run of a Macro.

EXAMPLE Delete Dictionary in One Action @kvanh.kmmacros (4.0 KB)

Click to Show Macro Image

EXAMPLE Delete Dictionary in One Action @kvanh

1 Like

@Zabobon, thanks for the feedback and thanks for sharing that nugget.

I've updated the post and the utility macro.

1 Like

FYI, I just uploaded version 3.0 of my Variable Inspector Prompt. It should make it even easier to create, edit, and delete dictionaries.

3 Likes

It does, thank you!

Others: If you are creating macros (with or without dictionaries), do yourself a big favor and download two of @DanThomas' indispensable tools:

2 Likes