This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
manual:Dictionaries [2017/09/04 02:04] peternlewis |
manual:Dictionaries [2021/05/31 03:33] ccstone [AppleScript] |
||
---|---|---|---|
Line 3: | Line 3: | ||
Keyboard Maestro includes permanently stored dictionaries that you can use or set. | Keyboard Maestro includes permanently stored dictionaries that you can use or set. | ||
- | A dictionary is a mapping from a key name to a value. You can have multiple dictionaries, each with their own name (so really, it is a mapping from a dictionary name and a key name to a value). | + | 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. | Dictionary names start with a alphabetic character, followed by any number of alphanumeric, space or underscores. Dictionary names are case insensitive. | ||
Line 10: | Line 10: | ||
Dictionary values are plain text and can include leading or trailing white space. | 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| | ||
===== Setting Dictionary Values ===== | ===== Setting Dictionary Values ===== | ||
Line 29: | Line 34: | ||
```applescript | ```applescript | ||
tell application "Keyboard Maestro Engine" | tell application "Keyboard Maestro Engine" | ||
- | name of dictionaries | + | set dictionaryNameList to name of dictionaries |
+ | end tell | ||
+ | ``` | ||
+ | |||
+ | ```applescript | ||
+ | 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 | end tell | ||
``` | ``` | ||
Line 35: | Line 53: | ||
```applescript | ```applescript | ||
tell application "Keyboard Maestro Engine" | tell application "Keyboard Maestro Engine" | ||
- | dictionary keys of dictionary "First Names" | + | set dictKeyList to dictionary keys of dictionary "Shop Prices" |
end tell | end tell | ||
``` | ``` | ||
Line 41: | Line 59: | ||
```applescript | ```applescript | ||
tell application "Keyboard Maestro Engine" | tell application "Keyboard Maestro Engine" | ||
- | set value of dictionary key "P" of dictionary "First Names" to "Fred" | + | set value of dictionary key "Coffee" of dictionary "Shop Prices" to "4.50" |
end tell | end tell | ||
``` | ``` |