MACRO: Dialog with Dynamic Popup List, v1.2


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 11.0.3
• Sequoia 15.4.1 (24E263)/MacBookPro18,2
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445


VERSION HISTORY

( expand / collapse )

1.0 initial version

1.1 No change to macro functionality. Defined local_DICT and used it rather than hard-coding dictionary name throughout.

1.2 No change to macro functionality. Applied techniques that I've since adopted in macros that I share:

  • Converted the complex header comment with the macro description: simplified it and added a link to the forum. This reduces that size of the macro in Keyboard Maestro plist. Also, the link provides a quick method to find the macro in the forum.

  • For conditional checks that do not require the any or all qualifier, changed IfThenElse actions to Switch/Case actions. Switch/Case actions have two advantages:

    • They occupy less vertical space in the macro editor.
    • When condition does not require an otherwise, it can be excluded.


Download: Dialog with Dynamic Popup List.kmmacros (51 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 15.4.1 (24E263)
  • Keyboard Maestro v11.0.3
5 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

2 Likes

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

2 Likes

@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

I've updated the OP with Version 1.2 of Dialog with Dynamic Popup List:

No change to macro functionality. Applied techniques that I've since adopted in macros that I share:

  • Converted the complex header comment with the macro description: simplified it and added a link to the forum. This reduces that size of the macro in the Keyboard Maestro plist. Also, the link provides a quick method to find the macro in the forum.

  • For conditional checks that do not require the any or all qualifier, changed IfThenElse actions to Switch/Case actions. Switch/Case actions have two advantages:

    • They occupy less vertical space in the macro editor.
    • When condition does not require an otherwise, it can be excluded.
1 Like