Applescript Menu

I’m making a voice-activated launcher that asks one what game one wants to play then launches the game. The only problem is I need a way to use applescript to add new games without editing the code. My code is below (customized for my sister Lauren) but I’d rather use arrays to manage games and possible pronunciations. Please Help! I’m somewhat of a newbie to Applescript, but I’ve been using it for two years (lightly).

Hi psobot,

You could use properties and subroutines to add games. When you declare the variable as a property, changes are saved. you can pass the subroutines any game in the list including those added. I didn’t use the speech stuff and just quickly modified your script as an example. Try running it several times in the script editor.

property choicesLanguageModel : {“add game”, “Bush fire”, “Marble”, “Marble Game”, “Marble Blast”, “Addicting Games”, “Internet”}
property helpLanguageModel : {“help”, “help me”, “what can i say”}
property thePrompt : “Hello Lauren. What game would you like to play today?”
tell application “SpeechRecognitionServer”
set theResultstring to “”
set theResultstring to listen for¬
choicesLanguageModel & helpLanguageModel with prompt¬
thePrompt giving up after 30
end try
end tell
set theResultstring to some item of choicesLanguageModel
if theResultstring is in choicesLanguageModel then
if theResultstring is “add game” then
display dialog “Enter the game name:” default answer “Some game”
set the_answer to text returned of result
set end of choicesLanguageModel to the_answer
– or you could save the application’s reference
end if
else if theResultstring is in helpLanguageModel then
– or call another suroutine
– do whatever
end if
on PlayGame(game_name)
say "Would you like to play the " & game_name & “?”
set bff to “yes”

tell application “SpeechRecognitionServer”
set bff to listen for (“yes”)
end tell
if bff is “yes” then
say "OK then. Starting the " & game_name & “.”

tell application game_name
end tell
end if
end PlayGame

You need to add more subroutines for the helpLanguageModel and think about what to do with the internet choices.


Hi psobot,

You might also use the ‘choose application’ standard additions command. Here’s an example of how you might fill a list with it:

property app_list : {}
set app_ref to (choose application)
set end of app_list to app_ref
repeat with this_app in app_list
activate this_app
end repeat


Thanks a lot! I’ll try that now.

The only problem with this is that what SpeechRecognitionServer listens for is not always the real name of the game. For example, saying Internet should launch Safari. Is there a way to cross-link two lists?

EDIT: Never mind; I found it on Apple’s site. Thanks for the help; I’ll post the script when I’m done.

I have come to another dilemma. How can I take the contents of list app_List and put them into a menu in the menu bar for this Xcode app?

the semi-finished script: