Keyboard Maestro includes permanently stored dictionaries that you can use or set.
A dictionary is a named set of mappings from a key name to a value. You can have multiple dictionaries, each with their own name (so really, it is a set of mappings from a dictionary name and a key name to a value).
Dictionary names start with a alphabetic character, followed by any number of alphanumeric, space or underscores. Dictionary names are case insensitive.
Key names can be anything, although leading and trailing white space is stripped off. Key names are case insensitive.
Dictionary values are plain text and can include leading or trailing white space.
For example, you might have a dictionary named “Shop Prices”, with keys being the item names and values being the cost of the item.
Dictionary | Key | Value |
---|---|---|
Shop Prices Shop Prices Shop Prices | Coffee Cake Drink | 3.45 5.35 2.50 |
You can use the %Dictionary% token to access Dictionary values.
%Dictionary[Shop Prices,Cake]%
%Dictionary[Shop Prices,%Variable%local_KeyName%]%
%Dictionary[%Variable%local_DictName%,%Variable%local_KeyName%]%
You can list the dictionaries with the Dictionaries collection, and you can list all the keys within a dictionary with the Dictionary Keys collection.
You can read and write dictionary values from AppleScript.
tell application "Keyboard Maestro Engine" set dictionaryNameList to name of dictionaries end tell
tell application "Keyboard Maestro Engine" set newDict to make new dictionary with properties {name:"Shop Prices"} # If you don't set a key/value pair the newly created dictionary above goes up in smoke. tell newDict make new dictionary key with properties {name:"Coffee", value:"3.50"} end tell end tell
tell application "Keyboard Maestro Engine" set dictKeyList to dictionary keys of dictionary "Shop Prices" end tell
tell application "Keyboard Maestro Engine" set value of dictionary key "Coffee" of dictionary "Shop Prices" to "4.50" end tell
See also the Set Dictionary Value action, the %Dictionary% token and the Dictionaries and Dictionary Keys collections.