Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interacting with Siri via the command line in macOS

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.

like image 750
Cory Klein Avatar asked Sep 28 '16 23:09

Cory Klein


People also ask

How do you use Mac command line?

In the Terminal app on your Mac, press the Up Arrow key. The last command you entered appears on the command line. Continue pressing the Up Arrow key until you see the command you want, then press Return.


3 Answers

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/

like image 159
Brad Parks Avatar answered Oct 21 '22 05:10

Brad Parks


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.

like image 26
steadystatic Avatar answered Oct 21 '22 06:10

steadystatic


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')
like image 4
Roman Avatar answered Oct 21 '22 05:10

Roman