Like to show idea/approach there you could use Node-RED to execute AppleScript. To send SSH from a remote computer (Linux or Raspberry Pi) that listen to inputs from microcontroller or any connection. Node-RED is not only used for IoT or Automation Industry. It could also be used in home automation.
The injected message is osascript.