I've created a command so that you can import existing Applescripts using a simple voice command. The script is in its early stages, and I've run into a few glitches. While MacSpeech Dictate's AppleScript dictionary defines commands as belonging to groups, it doesn't tie those groups to an application, or to a context. The upshot of this is that this script works for importing commands into the global group and any existing application groups. If you try to assign a script to a group that doesn't exist, it tries to create a group and fails and so does the script import.
I looked through the manual, and while it says that I can import scripts by dragging them into the window, that's still rather laborious process for someone like me, since I have tons of scripts that I've used for years with Apple's built-in speech recognition. If anyone with deeper knowledge of Dictate's scripting dictionary can help me connect the dots, I'd appreciate it.
The other element that is missing is the ability to compile the script under program control without opening the commands window and clicking the "compile" button. I think I've tried not compiling the script, closing Dictate, and reopening it and that this compiles the script, but of course that's the long way around.
I just called the command "Import Applescript into Dictate." Here's the script:
tell application "MacSpeech Dictate"
activate
set theFiles to choose file with prompt ¬
"Choose script(s) to import" of type {"com.apple.applescript.script", "osas"} ¬
with multiple selections allowed without invisibles
end tell
repeat with aFile in theFiles
tell application "Finder" to set theName to displayed name of aFile
tell application "MacSpeech Dictate"
activate
set theGroup to display dialog ¬
"What group should the command " & (quoted form of theName) & ¬
" belong to?" default answer "Global"
end tell
try
-- create alias
set theAlias to aFile as alias
-- get short name
-- get contents
tell application "Finder" to open theAlias
tell application "AppleScript Editor"
set theContents to contents of document theName
close document theName
end tell
-- make script
tell application "MacSpeech Dictate"
set newCommand to make new command with properties ¬
{name:theName, description:"Imported script", content:theContents, active:true, language:"en_US", command type:AppleScript, application name:theGroup}
end tell
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & ¬
the error_message buttons {"Cancel"} default button 1
end try
end repeat
tell application "AppleScript Editor" to quit
Kevin
