Unusual automation using my Mac Keyboard

If you have an SSH connection between your Home Assistant instance and your Mac you can use that to run Terminal commands on the mac. I used this guide from the forums and this guide from siytek.com (He has a couple typos in his guide… but it is pretty good)

Where the siytek.com guide has you create a new script, in Terminal on your Mac you can use something like:

#!/bin/bash

osascript -e 'tell application "**Your Application***" to activate' -e 'tell application "System Events" to key code 36'

The first “tell” isn’t absolutely necessary, it just brings your chosen application to the front. You can leave it off as long as you remember to leave the print dialog box activate on the desktop when you leave to go to the printer. The second “tell” is emulating pressing the Return key.

For me, the Home Assistant shell command configuration syntax that works is as follows:

#configuration.yaml

shell_command:
  mac_do_my_bidding: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] '~/press_my_button'
3 Likes