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:
• 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.
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]*
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.
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.
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.