How to Perform an Action Whenever the Typed String Buffer Is Empty?

I'm looking for a way to run a bash script whenever the Typed String Buffer is empty.

At the moment, I'm attempting to replicate the buffer with 3 macros:

  • One listening for all keypresses (regex period) and setting the "buffer" variable to %Variable%buffer%%TriggerValue%

  • One listening for option-backspace, which immediately runs the bash script.

  • One listening for backspace. If the length is > zero, it saves a substring of "buffer" to the source. If the length is zero, it runs the script.

There must be a better way, no?