"Type To Siri"


#1

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.

PREREQUISITES:

  1. First you must enable "Type To Siri" in System Preferences / Accessibility / Siri / "Enable Type To Siri"
  2. 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.

USAGE EXAMPLES:

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.

USAGE:

  1. Set the TypeToSiriQuery variable to a Siri query like "Turn Off Studio Light" etc.
  2. Run the Type To Siri Macro

    Type To Siri.kmmacros (52.6 KB)

Version 1.2 2019-03-28

  1. 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.
  2. As a result of 1. above, I have removed the 'repeat this action 2 times' because it should not be necessary any longer.

Demo of Keyboard Maestro to control Apple HomeKit
#2

Wow. Just wow. Did I say wow yet? That's 20 times more impressive than my primitive method for addressing HomeKit control. Your post is informative and innovative. Brilliant. AppleScript always makes me struggle so I'm really impressed. Very inspiring. I will study this. That's a whole different approach that I should have come up with myself... but didn't. Throw my old ideas away. I wonder what else can be done with this approach. I haven't even loaded your macro yet and I can see it's a winner. But it would sure be nice if the next release of KM could support this a little more directly with an action. After I study your solution I may propose a new action. But I hear it's on Peter's future feature list, so there's no point in pontificating.


#3

Thanks for sharing. This looks like a very cool & useful macro. :+1:
I'm looking forward to upgrading to Mojave so I can take advantage of features like this.


#4

Very cool!

You might like to use the parameter facility in the Execute a Macro action to pass your parameter instead of passing in a variable. You can always just start your macro with:

  • Set Variable TypeToSiriQuery to %TriggerValue%

to leave your macro unchanged.


#5

Updated to Version 1.2


#6

Thanks Peter, that's an interesting idea. Is there any other benefit besides the fact that I'll be able to remove the "Set Variable" action? I suppose I'll actually be moving & modifying the "Set Variable" action into the Execute Macro Action.


#7

It just means that when executing the macro you don't need to remember the name of the input variable.