Control iTunes with DragonDictate

Dragon Dictate controlling iTunes

DragonDictate for Mac can run custom commands triggered by a specific word or phrase. You say the word and Dragon triggers a shell script, AppleScript, open a bookmark, opens a file or document on your computer, and so on.

DragonDictate is set up so that the user (that’s you), leaves a small space/ pause before saying the name of a command to get it to run. It doesn’t really work because humans pause all the time and so when I tried this method I just got a lot of errors and annoying accidental commands and it was a gigantic pain. It’s easily fixed, though: I use a prefix word with my commands and I suggest you pick one too. I use “xylophone”, because xylophone just doesn’t come up in conversation that much. You can choose anything.

You create each command in basically the same way:

  1. choose the scope
  2. choose the type of action to be taken
  3. choose the name of the command
  4. then choose the action to be taken.

Controlling iTunes with your Voice

These commands control iTunes. They operate the standard play, pause, next track, previous track buttons, and the last one asks Growl to tell you about the current song.

(The main thing to know about writing good commands for voice recognition systems is to pair distinctive sounding words with your command. It’s the best way to cut down on the computer mistakenly doing things while you are just talking normally.)

The Dragondictate New Commands Interface

From the Tools menu in DragonDictate choose the Commands option and you’ll see the following interface:

DragonDictate Command Window

To create a new command from this window, you can either choose the New Command option from the File menu or use the keyboard shortcut Shift Command N.

This is what a blank commands window looks like:

DragonDictate Blank Command

As you can see you have options on the right-hand pane of the command window. This is where you can control the context, type, and action each of your commands will take.

In this case we are going to be using AppleScript commands only, so you need to change the following options for the command to play or pause iTunes.

  1. Command Name = Xylophone Toggle
  2. Command Description = This command will play iTunes if it is paused, and pause it if it is playing
  3. Context = Global (this means it will run when any application is foremost and not just one particular application is open, so you can have iTunes in the background.)
  4. Type = AppleScript
  5. The last option is a large window where we put the AppleScript. In this case the AppleScript needed is:
try
    -- Specify the application will want to work on, in this case iTunes.
    tell application "iTunes"
        -- Get iTunes current state
        if player state is paused then
            -- If iTunes is paused, press play.
            play
            -- Get iTunes state if it doesn't match the first condition
        else if player state is playing then
            -- If iTunes is playing, press pause.
            pause
        end if
    end tell
end try

Next, click the Compile button in the bottom left-hand corner and make sure your AppleScript is working properly (you will get an error if it isn’t), and finally click Save. This is what the finished item looks like:

Finished AppleScript

The iTunes Control Commands

Now that I’ve shown you how to create one of these commands in detail, I’m just going to post the AppleScript you need to accomplish each task. Everything stays the same as the first command; the only thing that changes is the name of the command and the AppleScript that runs when the command is issued.

iTunes Play/Pause Track

My verbal command is “Xylophone Toggle”

The AppleScript you need is:

iTunes Next Track

My verbal command is “Xylophone Next”

The AppleScript you need is:

iTunes Previous Track

My verbal command is “Xylophone Previous”

The AppleScript you need is:

iTunes Growl Information

This command is slightly different. If you want this feature, download and install Growl first.

My verbal command is “Xylophone Information”

The AppleScript you need is:

End

You can trigger any Applescript with Dragon in this way. I’ll be posting loads and loads of my little useful scripts for you to copy and use yourself, but you can also try writing your own. Good luck!