Command-line voice recognition with Mac OS X How can I do voice recognition on Mac OS X from the command line? Details: 

% When I look in ~/Library/Speech/Speakable Items, I see many files, 
 like "Tell me a joke", whose contents are: 

&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
&lt;!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"&gt; 
&lt;plist version="0.9"&gt; 
&lt;dict&gt; 
        &lt;key&gt;BuiltInCommandID&lt;/key&gt; 
        &lt;integer&gt;105&lt;/integer&gt; 
        &lt;key&gt;semanticCategory&lt;/key&gt; 
        &lt;string&gt;globalTellMeAJoke&lt;/string&gt; 
        &lt;key&gt;alternativeSpokenFeedback&lt;/key&gt; 
        &lt;string&gt;&lt;/string&gt; 
        &lt;key&gt;suppressSpokenConfirmation&lt;/key&gt; 
        &lt;string&gt;yes&lt;/string&gt; 
        &lt;key&gt;alternativeFeedback&lt;/key&gt; 
        &lt;string&gt;&lt;/string&gt; 
        &lt;key&gt;DefaultCommandName&lt;/key&gt; 
        &lt;string&gt;Tell me a joke&lt;/string&gt; 
&lt;/dict&gt; 
&lt;/plist&gt; 


% How does OS X know when to invoke this file? When I say something, 
 does it look for a matching filename? 

% How does OS X know what command to run? I see nothing in that file 
 that says what command to run ("Tell me a joke" is not a command-line 
 command). 

% I know there's some osacompile magic going on, but can't figure out 
 what it is. 

% How can I get OS X to listen for the string "s" and run the program 
 "cmd" in response? I'd prefer to do this purely from the 
 command-line, but if I have to open up a graphical program, I will.
You might be interested in reading Apple's documentation on Speakable Items, but the relevant part to your question, "How can I get OS X to listen for the string "s" and run the program "cmd" in response?" is:


  You can add an item to the Speakable
  Items folder to make it speakable.    
  
  To open something using a spoken
  command, just add it to the Speakable
  Items folder. You can use a command to
  open anything you can open by
  double-clicking, including
  applications, files, and Web sites.
  You can also write scripts and add
  them to the folder.


In regards to "How does OS X know what command to run? I see nothing in that file that says what command to run?", the relevant portion of the file you posted is:

    &lt;key&gt;BuiltInCommandID&lt;/key&gt; 
    &lt;integer&gt;105&lt;/integer&gt; 
    &lt;key&gt;DefaultCommandName&lt;/key&gt; 
    &lt;string&gt;Tell me a joke&lt;/string&gt; 


This is saying, when the spoken command "Tell me a joke" is received, run the internal command ID#105, which is the "Tell me a joke" command.

In this case you're looking at an internal command to the speech system. But you can add AppleScripts or shell commands to the speakable items folder as well.

This article on Mac OS X Hints may be helpful as well.

EDIT: After some research I am not sure if you can run shell scripts directly from there, but a little AppleScript wrapper would be easy enough to write, and you could even write it so it can be duplicated and renamed, and it would just run the corresponding shell script from /scripts or something.