Reputation: 1
My AppleScript
is working but if I wait a certain amount of time, even with the 'with timeout' statement, it times out. Can someone help? And respond quickly? It's due after a certain amount of time.
THANKS!!!!!!
Tell application "SpeechRecognitionServer
"
with timeout of 7200 seconds
set commands to listen for
{ "What are you?", "Identify yourself", "Take note", "Start Safari", "End Safari", "Start Mail", "End Mail", "Start Messages", "End Messages", "Start FaceTime", "End FaceTime", "Start Maps", "End Maps", "Play Music", "Start iTunes", "End iTunes", "Play", "Pause", "Next track", "Last track", "Make a Playlist", "Start AppleScript", "End AppleScript", "Start Calendar", "End Calendar" }
with prompt "Hello!
DELPHI is online! How can DELPHI help you today?"
if commands is "What are you?" then
say "I am DELPHI, created from the brilliant mind of Nathan!"
end if
if commands is "Identify yourself" then
say "Macintosh DELPHI virtual assistant version 1.0"
end if
if commands is "Take note" then
say "Press 'Enter' key to input what you said and press 'esc' key to cancel."
tell application "System Events"
keystroke "s" using {command down, shift down}
end tell
end if
if commands is "Start Safari" then
tell application "Safari"
activate
end tell
end if
if commands is "End Safari" then
tell application "Safari"
quit
end tell
end if
if commands is "Start Mail" then
tell application "Mail"
activate
end tell
end if
if commands is "End Mail" then
tell application "Mail"
quit
end tell
end if
if commands is "Start Messages" then
tell application "Messages"
activate
end tell
end if
if commands is "End Messages" then
tell application "Messages"
quit
end tell
end if
if commands is "Start Maps" then
tell application "Maps"
activate
end tell
end if
if commands is "End Maps" then
tell application "Maps"
quit
end tell
end if
if commands is "Start iTunes" then
tell application "iTunes"
activate
end tell
end if
if commands is "End iTunes" then
tell application "iTunes"
activate
end tell
end if
if commands is "Play" then
tell application "iTunes"
play
end tell
end if
if commands is "Pause" then
tell application "iTunes"
pause
end tell
end if
if commands is "Next track" then
tell application "iTunes"
next track
end tell
end if
if commands is "Last track" then
tell application "iTunes"
previous track
end tell
end if
if commands is "Make a Playlist" then
tell application "iTunes"
make user playlist with properties {name:"User Selections"}
end tell
end if
if commands is "Start AppleScript" then
tell application "AppleScript Editor"
activate
end tell
end if
if commands is "End AppleScript" then
tell application "AppleScript Editor"
quit
end tell
end if
if commands is "Start Calendar" then
tell application "Calendar"
activate
end tell
end if
if commands is "End Calendar" then
tell application "Calendar"
activate
end tell
end if
set commands to listen for {"What are you?", "Identify yourself", "Take note", "Start Safari", "End Safari", "Start Mail", "End Mail", "Start Messages", "End Messages", "Start FaceTime", "End FaceTime", "Start Maps", "End Maps", "Start iTunes", "End iTunes", "Play", "Pause", "Next track", "Last track", "Make a Playlist", "Start AppleScript", "End AppleScript", "Start Calendar", "End Calendar"} with prompt "Is there anything else I can do?"
if commands is "What are you?" then
say "I am DELPHI, created from the brilliant mind of Nathan!"
end if
if commands is "Identify yourself" then
say "Macintosh DELPHI virtual assistant version 1.0"
end if
if commands is "Take note" then
say "Press 'Enter' key to input what you said and press 'esc' key to cancel."
tell application "System Events"
keystroke "s" using {command down, shift down}
end tell
end if
if commands is "Start Safari" then
tell application "Safari"
activate
end tell
end if
if commands is "End Safari" then
tell application "Safari"
quit
end tell
end if
if commands is "Start Mail" then
tell application "Mail"
activate
end tell
end if
if commands is "End Mail" then
tell application "Mail"
quit
end tell
end if
if commands is "Start Messages" then
tell application "Messages"
activate
end tell
end if
if commands is "End Messages" then
tell application "Messages"
quit
end tell
end if
if commands is "Start FaceTime" then
tell application "FaceTime"
activate
end tell
end if
if commands is "End FaceTime" then
tell application "FaceTime"
quit
end tell
end if
if commands is "Start Maps" then
tell application "Maps"
activate
end tell
end if
if commands is "End Maps" then
tell application "Maps"
quit
end tell
end if
if commands is "Start iTunes" then
tell application "iTunes"
activate
end tell
end if
if commands is "End iTunes" then
tell application "iTunes"
quit
end tell
end if
if commands is "Play" then
tell application "iTunes"
play
end tell
end if
if commands is "Pause" then
tell application "iTunes"
pause
end tell
end if
if commands is "Next track" then
tell application "iTunes"
next track
end tell
end if
if commands is "Last track" then
tell application "iTunes"
previous track
end tell
end if
if commands is "Make a Playlist" then
tell application "iTunes"
make user playlist with properties {name:"User Selections"}
end tell
end if
if commands is "Start AppleScript" then
tell application "AppleScript Editor"
activate
end tell
end if
if commands is "End AppleScript" then
tell application "AppleScript Editor"
quit
end tell
end if
if commands is "Start Calendar" then
tell application "Calendar"
activate
end tell
end if
if commands is "End Calendar" then
tell application "Calendar"
activate
end tell
end if
end timeout
end tell
Upvotes: 0
Views: 1169
Reputation: 3792
One option is to place the listen command in a handler and call that from a repeat loop. It will repeat the listen after each command, or after each 60 second timeout:
set t to (current date) -- set a time stamp
set myCommands to {"Exit Delphi", "What are you?", "Identify yourself", "Take note", "Start Safari", "End Safari", "Start Mail", "End Mail", "Start Messages", "End Messages", "Start FaceTime", "End FaceTime", "Start Maps", "End Maps", "Play Music", "Start iTunes", "End iTunes", "Play", "Pause", "Next track", "Last track", "Make a Playlist", "Start AppleScript", "End AppleScript", "Start Calendar", "End Calendar"}
repeat 10 times -- will run for 10 commands and/or minutes
set c to listenFor(myCommands)
if c is "Exit Delphi" then
say "We're all done here."
exit repeat
else if c is "What are you?" then
say "I am DELPHI, created from the brilliant mind of Nathan!"
else if c is "Identify yourself" then
say "Macintosh DELPHI virtual assistant version 1.0"
else if c is "Take note" then
say "Press 'Enter' key to input what you said and press 'esc' key to cancel."
tell application "System Events"
keystroke "s" using {command down, shift down}
end tell
else if c is "Start Safari" then
tell application "Safari"
activate
end tell
else if c is "End Safari" then
tell application "Safari"
quit
end tell
else if c is "Start Mail" then
tell application "Mail"
activate
end tell
else if c is "End Mail" then
tell application "Mail"
quit
end tell
else if c is "Start Messages" then
tell application "Messages"
activate
end tell
else if c is "End Messages" then
tell application "Messages"
quit
end tell
else if c is "Start Maps" then
tell application "Maps"
activate
end tell
else if c is "End Maps" then
tell application "Maps"
quit
end tell
else if c is "Start iTunes" then
tell application "iTunes"
activate
end tell
else if c is "End iTunes" then
tell application "iTunes"
activate
end tell
else if c is "Play" then
tell application "iTunes"
play
end tell
else if c is "Pause" then
tell application "iTunes"
pause
end tell
else if c is "Next track" then
tell application "iTunes"
next track
end tell
else if c is "Last track" then
tell application "iTunes"
previous track
end tell
else if c is "Make a Playlist" then
tell application "iTunes"
make user playlist with properties {name:"User Selections"}
end tell
else if c is "Start AppleScript" then
tell application "AppleScript Editor"
activate
end tell
else if c is "End AppleScript" then
tell application "AppleScript Editor"
quit
end tell
else if c is "Start Calendar" then
tell application "Calendar"
activate
end tell
else if c is "End Calendar" then
tell application "Calendar"
activate
end tell
end if
end repeat
set t to ((current date) - t) as string -- return time stamp
return "Quit after " & t & " seconds."
on listenFor(commandList)
try -- a try block will capture the time out
tell application "SpeechRecognitionServer"
listen continuously for commandList with identifier "commands" with prompt "Speak a command or say: exit DELPHI"
set theResponse to result
stop listening for identifier "commands"
quit
return theResponse
end tell
on error err
-- timed out
return ""
end try
end listenFor
Ask, if you have any questions.
Upvotes: 1