This is a Macro that I wrote to control HomeKit with Siri using KM or other Scripts. Currently there is no direct way to control HomeKit with scripting (Mojave did introduce a Siri SDK "Sirikit", that Peter is now aware of, see: Can Siri Be Used to Trigger a KM Macro?).
This Macro utilizes Mac OS Mojave's "Type To Siri" feature in which you can activate a Siri prompt and type in text to ask Siri for information or for controlling HomeKit devices.
- First you must enable "Type To Siri" in System Preferences / Accessibility / Siri / "Enable Type To Siri"
- You may then modify how you 'activate' Type To Siri in System Preferences / Siri
NOTE: The default "Type To Siri" activation is "Hold Command Space", my macro uses "Hold Option Space", but you can change this to what you like in System Preferences, but be sure to then also change the Keystroke Action in the Macro.
The Macro runs some UI Scripts via AppleScript - which can sometimes be unreliable. I've tried to make them as reliable as possible while also adding some simple error notifications if something doesn't work. Problems may occur if you're running this on a Mac that's receiving lots of Notifications at the same time that the macro is run. As long as the "Type To Siri" notification window is the 'last' notification window shown, then it should work fine. I could fix this so that window order doesn't matter, but it wasn't necessary for my purposes as I have this running on a headless Mac Mini that's not receiving other notifications.
These are just some of the many things I execute with this macro.
I'm typically running remote KM Macros (from other Macs) that trigger this "Type To Siri" Macro on my Mac Mini. For instance, when I return to my Mac Pro after lunch and I move the mouse, the Lights and Speakers turn back on (if they were on previously).
I also have a Hard Drive Dock that I use for Backups. When it's time to run the backup, I have a KM macro use Type To Siri to turn on the Wifi / HomeKit switch that the Dock is connected to, and then the backup runs. When the backup finishes another KM Macro runs and checks to make sure the Backup Volume has been unmounted and then runs another Type To Siri command to turn the HomeKit switch off, thus turning the Dock off.
- Set the TypeToSiriQuery variable to a Siri query like "Turn Off Studio Light" etc.
- Run the Type To Siri Macro
Type To Siri.kmmacros (52.6 KB)
Version 1.2 2019-03-28
- Improved AppleScript code to 'find' the correct Notification Window for Type to Siri instead of having the window 'set' to 'first' or 'last' etc. This should make the macro a bit more reliable when there happens to be multiple notifications on screen.
- As a result of 1. above, I have removed the 'repeat this action 2 times' because it should not be necessary any longer.