OS X Yosemite has a new feature called Dictation Commands. This allows you to press Function key twice, speak your command, and then have the computer do something for you. While there are some useful built in ones, it is much more interesting to make your own.
Create A Voice-activated Command For Your Mac
Enable Enhanced Dictation
Enable this feature in the Dictation & Speech section of System Preferences. Make sure to check the box for Offline dictation. If it is not already enabled, your computer will start to download a large package containing the voice recognition.
Use Automator To Make A Custom Voice-activated Workflow
Open Automator then choose Dictation Command
Create a workflow similar to the one below.
- Open Automator
- In the Dictation Command: field, enter a name
- Search for Run Shell Script in the field on the top-left
- Drag-and-drop the result onto the blank area to the right
- Write your script
You can run basically any command or action you want. I don’t actually erase my hard drive above, but I make the computer say (in a female computer voice) that the self-destruct sequence has been initiated. You could also have fun with this and use afplay to play an audio file such a real Star Trek one for that authentic feel.
The commands mentioned like rm -rf / will not actually run without some hacking. The biggest problem you will run into is that it needs elevated credentials, such as using sudo , which requires you enter a password. While there are ways around this, I won’t mention them here in this article. You could, however, use a similar command to delete a folder or file that you have access to, such as any file in your home directory.
After saving your workflow, you will find an app was created in /Users/<your_user>/Library/Speech/Speakable Items .
Enable Advanced Dictation Commands
Next, open System Preferences > Accessibility > Dictation and click Dictation Commands… Make sure the Advanced Commands checkbox is enabled. Since you created the command in Automator, it should automatically show up.
If you have other previously-made workflows that you want to connect to a voice command, just click the + button to create a new command fill in the information to run your app.
Execute Your Voice Command
Now, tap the Function key twice and you will get a small microphone icon and you should hear the Siri sound. Say your command and your workflow will run.
When your command is detected, it will display above the microphone icon.