Create Dictionary

Description: Facilitates easier creation and updating of dictionaries from a formatted string, utilising a simple and flexible syntax that will hopefully feel comfortable to anyone familiar with one of the common declarative scripting languages from which this borrows.

Syntax overview

Key-value pairs declared one per line, contained within brackets or braces following the name of the dictionary that is to be created or modified. See the image above for an example. An alternative form is:

${dictionary-name} : [
	${key}=${value}
	${key}=${value}
		.
		.
		.
]

Guidance notes: Either square brackets [...] or curly braces {...} may be used to delimit the start and end of the dictionary contents within which {key, value} pairs are declared and needn't be a matching pair. The opening delimiter is preceded by the name of the dictionary; a colon may optionally follow the name of the dictionary but can be omitted. {key, value} pairs are declared on individual lines, using either a colon :, a bar |, or an equals sign = as the delimiting character. Keys, values and the dictionary name can contain spaces, but leading and trailing whitespace for all identifiers and delimiting punctuation is ignored, as are blank lines. This macro does not currently cater for values that contain newline characters.


image  Create Dictionary.kmmacros (43.5 KB)

2 Likes

Very nice! :+1:

Since you are also familiar with KM Plugins, any chance that you might offer this as a Plugin?

Also, the input format you provide is very close to JSON format. It would be very nice and powerful to allow JSON as an option, both for input and output.

Nice ideas. I'll get to work on these.

1 Like

Be aware that JSON support for setting dictionaries (or variables) from JSON is built in to Keyboard Maestro 9, so any work you do on this may be made redundant (or much easier) when it is released.

Not that that should necessarily dissuade you from doing it in the mean time, and it will still be useful to anyone who does not end up upgrading.

2 Likes