AppleScript错误号-1712

时间:2014-06-08 06:52:13

标签: applescript

我的AppleScript正在运行,但如果我等待一段时间,即使使用'with timeout'语句,它也会超时。有人可以帮忙吗?并快速回应?这是在一段时间后到期的。

感谢!!!!!!

告诉应用程序“SpeechRecognitionServer” 超时为7200秒 设置命令以侦听

  

{“你是什么?”,“识别自己”,“记笔记”,“启动Safari”,   “结束Safari”,“开始邮件”,“结束邮件”,“开始邮件”,“结束   消息“,”开始FaceTime“,”结束FaceTime“,”开始地图“,”结束地图“,   “播放音乐”,“启动iTunes”,“结束iTunes”,“播放”,“暂停”,“下一步   track“,”Last track“,”Make a Playlist“,”Start AppleScript“,”End   AppleScript“,”开始日历“,”结束日历“}

提示“你好!

  

DELPHI在线! DELPHI今天如何帮助您?“

    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

1 个答案:

答案 0 :(得分:1)

一个选项是将listen命令放在处理程序中并从重复循环中调用它。它将在每个命令之后或每60秒超时后重复监听:

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

问,如果您有任何问题。