User Tools

Site Tools


manual:Dictionaries

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
manual:Dictionaries [2017/09/04 01:54]
peternlewis [See Also]
manual:Dictionaries [2021/10/04 03:20]
peternlewis [Accessing Dictionary Values]
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 15: Line 20:
 Use the [[action:​Set_Dictionary_Value#​See_Also|Set Dictionary Value]] action to set a dictionary value. Use the [[action:​Set_Dictionary_Value#​See_Also|Set Dictionary Value]] action to set a dictionary value.
  
 +{{:​manual:​set_dictionary_key_example_01.png|}}
 +
 +{{:​manual:​set_dictionary_key_example_02.png|}}
 +
 +{{:​manual:​set_dictionary_key_example_03.png|}}
 ===== Accessing Dictionary Values ===== ===== Accessing Dictionary Values =====
  
 You can use the [[token:​Dictionary|%Dictionary%]] token to access Dictionary values. You can use the [[token:​Dictionary|%Dictionary%]] token to access Dictionary values.
  
-{{:token:dictionary-example.png?​nolink&​568|}}+{{:manual:dictionary_01.png}} 
 + 
 + 
 +''​%Dictionary[Shop Prices,​Cake]%''​ 
 + 
 +{{:​manual:​dictionary_02.png}} 
 + 
 +''​%Dictionary[Shop Prices,​%Variable%local_KeyName%]%''​ 
 + 
 +{{:​manual:​dictionary_03.png}} 
 + 
 +''​%Dictionary[%Variable%local_DictName%,​%Variable%local_KeyName%]%''​ 
 + 
 +You can list the dictionaries with the [[collection:​Dictionaries|Dictionaries]] collection, and you can list all the keys within a dictionary with the [[collection:​Dictionary_Keys|Dictionary Keys]] collection. 
 + 
 + 
 +===== AppleScript ===== 
 + 
 +You can read and write dictionary values from AppleScript. 
 + 
 +```applescript 
 +tell application "​Keyboard Maestro Engine"​ 
 + 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 
 +``` 
 + 
 +```applescript 
 +tell application "​Keyboard Maestro Engine"​ 
 + set dictKeyList to dictionary keys of dictionary "Shop Prices"​ 
 +end tell 
 +``` 
 + 
 +```applescript 
 +tell application "​Keyboard Maestro Engine"​ 
 + set value of dictionary key "​Coffee"​ of dictionary "Shop Prices"​ to "​4.50"​ 
 +end tell 
 +```
  
 ===== See Also ===== ===== See Also =====
  
 See also the [[action:​Set_Dictionary_Value|Set Dictionary Value]] action, the [[token:​Dictionary|%Dictionary%]] token and the [[collection:​Dictionaries|Dictionaries]] and [[collection:​Dictionary_Keys|Dictionary Keys]] collections. See also the [[action:​Set_Dictionary_Value|Set Dictionary Value]] action, the [[token:​Dictionary|%Dictionary%]] token and the [[collection:​Dictionaries|Dictionaries]] and [[collection:​Dictionary_Keys|Dictionary Keys]] collections.
manual/Dictionaries.txt · Last modified: 2021/10/04 03:24 by peternlewis