Possible to run script based on result of code evaluation?

I'm building a sort of tidalcycles raspberry pi zero cybderdeck. Here's what I envision:

  • I run tidalvim
  • when I evaluate some tidal code and it's successful, a script is run to turn on one of the GPIO pins (green led)
  • if the code I evaluate has an error (invalid syntax etc) a script is run to turn off the green led and activate another GPIO pin with a red LED


  • because it would be cool
  • if I had this functionality, I wouldn't necessarily have to have the "tidal>" window open, so I could maximize my actual coding real estate

is there any way to do this? I know I can do the GPIO stuff, I'm just not sure about the "run a script on error" part