Update macros programmatically

Is it possible to load or update a macro group programmatically or based on an external file?

Here's my use case:

TextExpander has the ability to read and load snippets from an external file. Before they switched to their subscription pricing model and I switched to Keyboard Maestro for text expansion, I had a group that I added based on an external file was generated with a script that runs every few hours (the script parses a bunch of BibTeX files (bibliography files for LaTeX) and saves their unique citation keys to a local file). I then used TextExpander's “Search Snippets” hotkey to search and insert the citekeys as I write.

Keyboard Maestro appears to have very similar capabilities, especially with its group-specific palettes (i.e. it would be really easy to search in a list of macros). It's easy enough to make a bunch of simple macros (like the fake Smith, Jones, and Johnson entries in this screenshot), and then use a palette to insert them:

However, I have not found a way to programmatically update that list of macros (i.e. every few hours, check the list of citation keys and refresh it in Keyboard Maestro). Is there a way to have a macro group load or import macros from an external file? Or, barring that, perhaps a way to use Applescript or something to redefine macros?

I can think of numerous ways of accomplishing this. Let's start with the easiest first and work our way forward from there.

If you can live with a simple drop-down list of snippets, you could use a Prompt action. As long as the snippets don't contain the "bar" character "|" and aren't multi-line, you could have a prompt like this:

Here's an example of how to do this - if you need to sort the list, just ask.

Snippet Prompt.kmmacros (3.6 KB)

This macro has a hard-coded path to a file in Documents named "MySnippets.txt" (which you need to create). You can change the path as needed.

If you wanted a version where you could search the dropdown list by typing, I could create a Custom HTML Prompt for you to do this.

Let me know if this will work, or if you want something else.

Thanks for the suggestions Dan!

I used ideas from your other forum posts and combined them with Nik's fancy Mac-like HTML prompts to create my own autocomplete HTML prompt: km-citekeys

2 Likes

Awesome! You’ve even got a cool icon. I love it!

Well, that’s from BibDesk :slight_smile:

Yeah, but it looks cool in the prompt. :slight_smile:

1 Like