Brevis — Automating Text Expansions

Last Updated: April 10, 2022 • Version 1.2a

Brevis (ars longa, vita brevis or endless work, brief life) is a compact, efficient system for managing a collection of single action, insert-text expansions triggered by typed strings.

ss-319

In short, it automates Keyboard Maestro text expansions.

HIGHLIGHTS

  • A single three-macro system for all text expansions

  • Text expansions are organized in categories that can be filtered for display

  • One global variable stores all your text expansions (including emoji and special characters) so your Keyboard Maestro plist doesn't expand when you add an expansion

  • The initial character of the typed string trigger modifies behavior, inserting by pasting or typing and dropping or keeping the trailing character

  • Support for Keyboard Maestro tokens, including the insertion point token (%|%)

  • Includes two optional utility macros to edit your text expansions in a text editor

  • Compatible with existing Keyboard Maestro text expansion macros, with which it does not conflict

  • Control Panel to list, filter, add, delete, export and import expansions

  • Create a text expansion from selected text with error checking

DESCRIPTION

Rather than using the Keyboard Maestro editor itself to manage a collection of separate macros for each text expansion, Brevis provides both 1) an easy-to-use Control Panel to create, run, list, export, import and merge them as well as 2) a faceless way to create and run them.

Whether you need a quick text expansion temporarily or can’t remember the ones you’ve already recorded, Brevis quickly comes to the rescue. The Control Panel can function as a palette of expansions as well as provide a quick interface for maintenance functions.

DOWNLOADS

Here's the v1.2a Control Panel macro:

Brevis.12a.zip (10.8 KB)

12 June 2023: Added a warning to the Edit utility to prevent accidentally wiping out the Brevis variable.

18 September 2021: Replaced Brevis.11c.zip with minified JavaScript code, saving 1K.

5 October 2021: Corrected an error in the Create from Selection macro's pattern for the trigger.

10 April 2022: Fixed an issue with multiple exports, smartened up Import option to do what Merge did, dropping Merge. Added a sample emoji import with the updated documentation and existing dates import.

ss-320

(When I first started working on this macro app, Jim Underwood (JMichaelTX) responded to my request for help with an AppleScript to parse the Keyboard Maestro plist. While that did what I wanted, what I wanted wasn't practical and I took the approach used in this macro, skipping the plist in favor of a global variable. Our pleasant exchange was the last I had with him (among many others over the years) before his untimely passing. This contribution is in tribute to him and the assistance he generously gave here.)

14 Likes

:slight_smile: I might be tempted to nuance that translation towards something like – skills take long to master, life is short.

Or visually, in the many renderings of the vanitas theme ...

1 Like

Does it show a conflict palette or some way to select between two expansions that use the same text trigger?

It prevents adding an expansion that uses a trigger already in the collection when you use its methods for adding expansions.

If you manually add a conflict using the editing utility or by typing one into the variable in the Keyboard Maestro Editor, it just uses the first one it finds and ignores the second.

But by design it assumes the triggers are unique.

Regarding existing expansions outside Brevis, those would have priority by virtue of not requiring a closing non-word character. And if by chance, they do require one, you can simply use a different one for the Brevis trigger to avoid a conflict.

1 Like

Just a note to report I've updated the Brevis.11c.zip file with a new version of the (unversioned) Create from Selection macro that corrects the trigger pattern so you can enter any legal trigger.

@mrpasini Thanks for you great macro. i install it, but i have no way to trigger the regexp [,;=+*^][:alpha:][[:alnum:]-]+\W. is there any sample?

If none of the several triggers work, it could be because you didn't Enable the Run Brevis macro in the suite. And if that's the case, make sure the others are enabled, as well as the whole group.

Brevis 1.2a Released

Fixed an issue with multiple exports, smartened up Import option to do what Merge did, dropping Merge. Added a sample emoji import with the updated documentation and existing dates import.

ss-320

I've updated the original post with the new version, which supercedes earlier versions.

3 Likes

Hello @mrpasini!

I was testing Brevis and added one expansion. That worked fine. Then I used the Edit util and then Save util while BBE was open. Edit util created a json file containing my expansion. So far, so good ...

I must have hit a wrong key because now Brevis doesn't work anymore. I've deleted the group, rebooted my iMac, reinstalled Brevis and still it doesn't work.

When I try to add a macro either by selecting a string in BBE first and then opening the Control Panel or without selecting a string first, I can type the category ('ABB') and trigger ('foxe') and the text (The quick brown ...). When I click on OK, I hear a beep.

When I use Utility: Edit, the Text 'Utility: Save' is pasted into a BBE window.

How can I reset Brevis completely? Obviously, rebooting didn't reset it.

Thank you in advance!

1

The Edit and Save utilities are dangerous stuff, mainly for heavy duty editing of existing macros. Because they expose the JSON formatting, it's easy to screw them up. A missing comma will do it.

The documentation details a safe way to edit a macro (play the old one, edit it, delete it with the Control Panel, create the revision by selecting the new text). I thought about adding an Edit option but I rarely need it.

Anyway, to answer your question, open the Keyboard Maestro editor, select Preferences and visit your Variables. Find the Brevis global variable and just delete the contents. That creates an empty but JSON-legal variable. Brevis should run normally after that.

If you had a lot of macros already, I'd suggest you use the Same utility to save them to a file so you wouldn't have to recreate them. Then you can run that data through an online JSON validator like https://jsonlint.com to find and fix the error before using the Save utility to restore your macros.

Hope that helps.

1 Like

Thank you @mrpasini for answering my question and offering the solution. Brevis is up and running again.

I now remember that I edited the single entry in the exported JSON file. Must have made a mistake there.

If you don't mind me asking: Why are you using the complex (at least in my eyes) and 'bulky' JSON format? Why not use a simple tab-delimited list, that can be edited in any spreadsheet program and probably can also be imported in several CAT tools, wordprocessors etc. that have an auto-complete or auto-suggestion feature?

This is not meant as criticism, far from that: I'm just wondering...

A tab-del file could look like:

foxe\tThe quick brown fox jumps over the lazy dog.\tabb
foxd\tZwölf Boxkämpfer jagen Viktor zum Spaß quer über den Sylter Deich.\tabb
foxnl\tPa's wijze lynx bezag vroom het fikse aquaduct.\tabb
home\tPaleis Het Loo, Soestdijk\tadr
work\tPaleis Het Einde, Den Haag\tadr

Or, even more compact:

#abb
foxe\tThe quick brown fox jumps over the lazy dog.
foxd\tZwölf Boxkämpfer jagen Viktor zum Spaß quer über den Sylter Deich.
foxnl\tPa's wijze lynx bezag vroom het fikse aquaduct.
#adr
home\tPaleis Het Loo, Soestdijk
work\tPaleis Het Einde, Den Haag

Would it be possible to make the expansion case-adaptive?

So ',foxe' gives 'The quick brown fox jumps over the lazy dog.' but ',FOXE' gives 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'

This simple answer (and, no, I don't mind you asking), is that I wanted to use tabs themselves in the replacements. So I wanted a standard data format that could accommodate that. Any other application looking at the data would understand it.

Yes, I could have reinvented the wheel and escaped the tab (eg: \\t) -- and JSON does require escaping its own delimiters -- but no other application would have known what Brevis was doing.

The 'bulky' JSON format (you're right, it isn't as efficient as it might be) is greatly mitigated by using single character field names and compacting the format (not prettifying it). What you saw when you used the Edit utility is quite different from what you see when you look at the global variable Brevis. Indeed, compared to separate Keyboard Maestro macros, Brevis represents a substantial space savings in your Keyboard Maestro plist. Somewhere in the documentation, I give an example of that.

For Glossarium, I used new lines to delimit its three known fields rather than JSON because I wanted the data file to be human readable as the primary text entry vehicle. That's not a requirement in this case. Just the opposite.

JSON is, in fact, well supported. You can import JSON-formatted data into Excel and Numbers and other applications without knowing anything about the format.

I don't see the advantage of auto complete in a text expansion context. You don't need (or want) auto complete in that context, it seems to me.

I don't mind discussing the design decisions I made. They certainly evolved through several prior unreleased versions of this macro set. Before anything gets here, I've beaten it to death. :grin:

Keyboard Maestro does have an option to convert case depending on the trigger but it is not available when you use the regex trigger, as Brevis does.

So Brevis itself would have to distinguish between a trigger that happens to use uppercase and one that intentionally uses it to force case conversion. If you use =USA to expand to United States of America you might get UNITED STATES OF AMERICA unless Brevis understood from =USA alone which you wanted.

The solution to this is using separate expansions for each case. So =Usa might expand to title caps and =USA would work for Space Shuttle decals. There's no duplication involved in the JSON variable.

Hope that answers your (very good) questions. Thanks for asking.

Going to give this a try: neat not to have to use a separate app (perhaps w/questionable privacy practices) :slight_smile:

=mrp:

mrpasini devotes an astounding amount of his free time to complete strangers, and it is simply beautiful

NOICE. Thanks!

...19 page PDF explaining a 100% free, ad-free, everything-free tool... you the real MVP!

2 Likes

:face_with_hand_over_mouth: Very kind of you!