Question about using dictionaries

I have a macro which calls a legal opinion cite from a text file contained in a folder of text files, each of which contains a single case cite. In other words, when I provide certain input, the macro searches the folder for the right file, reads the file, thus collecting the single line of text in the file (which is the case cite), loads the cite onto the clipboard, occasionally performs manipulations on it, and pastes it into my document. This is not the same as a text expansion use case.

My question is: is my folder of text files essentially a dictionary, and does KM allow the construction of dictionaries like my folder of text files, potentially containing hundreds or even thousands of key values?

Well, "dictionary" is somewhat a matter of definition, but it sounds like your data structure is more complicated than a Key/Value pair, which is the basic structure of a simple dictionary.

IMO, dictionaries in general, and KM's implementation of dictionaries specifically, do not lend themselves to large amounts of data. Certainly, for thousands of records, I would consider a SQL database.

A SQL database would have these advantages:

  1. Very fast data search and retrieval
  2. Provide multiple fields (properties) for each cite that you might find useful (like date, source, cases, etc)

Having said all that, this is such an old, common use case, that I would expect you could find a number of existing tools to provide legal cites.

Also, for KM, I have found it best to store large amounts of data outside of KM to prevent more bloat to the master KM Macro file, and to provide better access, backup, editing, and sharing.

1 Like

JMichaelTX makes sense about the 1) bloat and 2) unwieldyness of an internal Keyboard Maestro solution. But it seems to me you have another option which you're halfway to already.

Instead of one file with a citation, why not one file for all the citations using the current filename key as the text key in citations file?

Instead of looking for filenames, you'd search for the same text in your citations file and simply retrieve the citation following it using a regexp.

The citations file might look like this (in the abstract):

[key to search]
[the citation, cleaned up as it would have been in the clipboard perhaps or not]

[key to search]
[the citation, cleaned up as it would have been in the clipboard perhaps or not]

And your regexp would simple look for the ([key])\n([citation])\n\n and if [key] matches ($1), paste the [citation] $2. I'm using returns to separate the items but if the citations have returns in them, use another character or set of them.

That would make it easy to backup your citations or make them portable and even group them in different categories without the bother of learning the ins-and-outs of MySQL or some database software.

1 Like

Well, once again your idea, @BKammer, intrigued me.

I've put together a macro that reads a 16K file of terms and definitions (a glossary) and if you use one hot key trigger will replace a selection in your text with the definition or, if you use another, will simply display the key and definition in a popup window.

The text file is easy to maintain and stays out of the Keyboard Maestro macro file. It can also accommodate a large number of substitutions in just one macro and doesn't require learning a database language.

It does just make one substitution at a time or display just one entry at a time. So it isn't appropriate for enforcing a publication style, for example.

If you (or anyone else reading this) is interested, I'll be happy to share when I work out the text in the glossary.


Nice! I ended up taking your and @JMichaelTX's suggestions to heart. I created a single text file with a key:value structure and accessed the elements via regex. Works like a charm and seems more efficient and manageable. Thank you!

@JMichaelTX, I think my folder does approximate a fairly simple dictionary. The filename of the text file is the key, and the single line in the body of the text file is the value.

Neither here nor there, but my macro system for legal writing is designed to manipulate case citation text quickly rather than locate case cites. Of course, I rely on other tools for that. I also use KM as a text expander to output accurate case citations without having to look up the citations.