18

I use Siri on my phone and watch to create reminders on the go. When I'm in the office I don't want to disturb the quiet by using Siri, so I usually use an Alfred workflow that is integrated with the Reminders app, or use the Reminders app directly.

However, both have a rather clunky interface, and it would be much easier if I could just type at the command line:

$ siri "remind me to check stack overflow for responses to my question in 15 minutes"

macOS Sierra has introduced Siri to the desktop, but so far I have been unable to find a way to interact with Siri in any way other than literally talking out loud, and Spotlight does not match Siri with natural language comprehension.

Apple has announced the Siri SDK, but it seems primarily related to adding functionality to Siri, not for exposing the Siri API.

Does Apple expose any kind of API to Siri on macOS such that one could make Siri requests via the command line, system call, or other executable?

Note: I understand that this question could conceivably find a better home at Ask Different, Super User, or Unix & Linux. In the end, I decided that some programmatic integration with an API or SDK was the most probable solution, and thus Stack Overflow seemed the most appropriate place to post. If mods disagree, please do migrate to whichever community is best.

Cory Klein
  • 51,188
  • 43
  • 183
  • 243
  • 1
    Just installed the Sierra update and had the same thought as you. Don't want to talk to Siri in the office. Would rather just type commands in bash. This should be a natural feature to have, since Siri's first job upon hearing a command most likely involves parsing that command to text. – rtm Oct 11 '16 at 17:44

4 Answers4

8

I was wanting the same feature today - I got it working but could be improved upon: https://youtu.be/VRLGCRrReog

TLDR is use LoopBack by Rogue Amoeba and change Siri’s input Mic to Loopback. Then Use the Say command in Terminal for example.

8

This isnt from the command line, but closer... and I haven't tested it, but in High Sierra there's a way to use Accessibility settings to enable you to use your keyboard to ask Siri questions.

How to enable it:

  • System Preferences > Accessibility > Siri.
  • Click in the box beside Enable Type to Siri so that a tick appears.
  • Now when you trigger Siri, a keyboard will appear into which you can type your query.

Snagged from here: https://www.macworld.co.uk/news/mac-software/how-use-siri-on-mac-3536158/

Community
  • 1
  • 1
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
5

As mentioned by Brad Parks, you can enable 'Type to Siri' from the Accessibility menu. You can use this to interact with Siri using simulated keypresses.

I've created a simple Python script which behaves like requested in your question when invoked from the command line.

The script uses the keyboard Python module.

#!/usr/bin/python
import sys
import time
import keyboard

def trigger_siri():
    keyboard.press('command+space')
    time.sleep(0.3)
    keyboard.release('command+space')
    time.sleep(0.2)  # Wait for Siri to load

if __name__=='__main__':
    trigger_siri()
    keyboard.write(sys.argv[1])
    keyboard.send('enter')
Roman
  • 163
  • 1
  • 2
  • 7
3

Cliclick is a great (and free) tool for triggering mouse and keyboard events via the command line. After installing Cliclick, I enabled "Type to Siri" (System Preferences > Accessibility > Siri). I also changed Siri's keyboard shortcut to "Press Fn (Function) Space" (System Preferences > Siri). The other keyboard shortcut options require you to "Hold" a key, which can be done, but it makes things a bit trickier.

With all that done, I can invoke Siri from the terminal with something like this:

$ cliclick kd:fn kp:space ku:fn w:250 t:"turn on the living room lights" kp:return

Going a step further, if you are familiar with terminal aliases and functions, you can create a "siricli" function:

siricli(){
    cliclick kd:fn kp:space ku:fn w:250 t:"$1" kp:return
}

Open a new terminal window after adding that function, and now you can invoke Siri from the command line like this:

siricli "turn on the living room lights"