Applescript “如何显示对话框”;“错误”;当变量返回错误答案时

Applescript “如何显示对话框”;“错误”;当变量返回错误答案时,applescript,voice-recognition,dictating,Applescript,Voice Recognition,Dictating,好的,我的代码在下面,当我输入一个拼写错误的单词或一个没有意义的短语时,它会显示一个带有“msng”的对话框,但我想显示一条错误消息。如果答案是/包含“msng”,我尝试使用这两种答案,然后。。。但这是行不通的,任何帮助都是感激的 tell application "Safari" quit end tell set defaultAnswer to "" set cancelButton to "Cancel" set buttonResearch to "ReSearch" di

好的,我的代码在下面,当我输入一个拼写错误的单词或一个没有意义的短语时,它会显示一个带有“msng”的对话框,但我想显示一条错误消息。如果答案是/包含“msng”,我尝试使用这两种答案,然后。。。但这是行不通的,任何帮助都是感激的

tell application "Safari"
    quit
end tell

set defaultAnswer to ""
set cancelButton to "Cancel"
set buttonResearch to "ReSearch"

display dialog "Query: " default answer defaultAnswer buttons {cancelButton, buttonResearch} default button buttonResearch cancel button cancelButton with icon 1
copy the result as list to {button_pressed, text_returned}

tell application "Dragon Dictate"
    set listening to false
end tell

if (button_pressed is buttonResearch) and (text_returned is not "") then
    set theUrl to "http://www.wolframalpha.com/input/?i=" & encode_text(text_returned, true, false)
    tell application "Safari"
        tell window 1 to set current tab to (make new tab with properties {URL:theUrl})
        tell me to say "let me look that up for you now"
        tell document 1
            repeat -- wait until loaded
                delay 2
                if (do JavaScript "document.readyState") = "complete" then exit repeat
            end repeat
            do JavaScript "document.getElementById('pod_0200').getElementsByClassName('action subpod-copyablept ')[0].click()" -- show the popup window
            set theAnswer to do JavaScript "document.body.lastChild.getElementsByTagName('pre')[0].innerHTML;" -- get the answer in this popup window
        end tell
    end tell
    activate

    if theAnswer contains "msng" then
        display dialog "There was an error, you may have misspelled a word or phrased it incorrectly"
    else
        display dialog theAnswer
    end if

end if

tell application "Safari"
    quit
end tell

-- encoding high-ASCII characters:
on encode_char(this_char)
    set the ASCII_num to (the ASCII number this_char)
    set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
    set x to item ((ASCII_num div 16) + 1) of the hex_list
    set y to item ((ASCII_num mod 16) + 1) of the hex_list
    return ("%" & x & y) as string
end encode_char

-- TEXT ENCODING: encode spaces and high-level ASCII characters (those above 127)
-- encode_URL_A = encode most of the special characters reserved for use by URLs.
on encode_text(this_text, encode_URL_A, encode_URL_B)
    set the standard_characters to "abcdefghijklmnopqrstuvwxyz0123456789"
    set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
    set the URL_B_chars to ".-_:"
    set the acceptable_characters to the standard_characters
    if encode_URL_A is false then set the acceptable_characters to the acceptable_characters & the URL_A_chars
    if encode_URL_B is false then set the acceptable_characters to the acceptable_characters & the URL_B_chars
    set the encoded_text to ""
    repeat with this_char in this_text
        if this_char is in the acceptable_characters then
            set the encoded_text to (the encoded_text & this_char)
        else
            set the encoded_text to (the encoded_text & encode_char(this_char)) as string
        end if
    end repeat
    return the encoded_text
end encode_text
告诉应用程序“Safari”
退出
结束语
将defaultAnswer设置为“”
将取消按钮设置为“取消”
将按钮ReSearch设置为“ReSearch”
显示对话框“查询:”默认回答默认回答按钮{cancelButton,buttonResearch}默认按钮按钮搜索取消按钮取消按钮图标1
将结果作为列表复制到{按下按钮,返回文本}
告诉应用程序“龙口述”
将侦听设置为false
结束语
如果(按下的按钮是buttonResearch)和(返回的文本不是“”),则
将URL设置为“http://www.wolframalpha.com/input/?i=编码文本(返回的文本,真,假)(&encode)
告诉应用程序“Safari”
告诉窗口1将当前选项卡设置为(使用属性{URL:theUrl}创建新选项卡)
告诉我说“让我现在帮你查一下”
告诉文件1
重复--等待加载
延迟2
如果(do JavaScript“document.readyState”)=“complete”,则退出repeat
结束重复
执行JavaScript“document.getElementById('pod_0200')。getElementsByCassName('action subpod copyablept')[0]。单击()”--显示弹出窗口
将答案设置为执行JavaScript“document.body.lastChild.getElementsByTagName('pre')[0].innerHTML;”--在该弹出窗口中获取答案
结束语
结束语
激活
如果答案包含“msng”,则
显示对话框“出现错误,您可能拼写错误或措辞不正确”
其他的
显示回答对话框
如果结束
如果结束
告诉应用程序“Safari”
退出
结束语
--编码高ASCII字符:
关于编码字符(此字符)
将ASCII_num设置为(此字符的ASCII编号)
将十六进制列表设置为{“0”、“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“A”、“B”、“C”、“D”、“E”、“F”}
将x设置为十六进制列表的项目((ASCII_num div 16)+1)
将y设置为十六进制列表的项((ASCII数mod 16)+1)
以字符串形式返回(“%”&x&y)
结束编码字符
--文本编码:对空格和高级ASCII字符(127以上的字符)进行编码
--encode_URL_A=对URL保留使用的大多数特殊字符进行编码。
在encode_text(此_text,encode_URL_A,encode_URL_B)上
将标准字符设置为“abcdefghijklmnopqrstuvwxyz0123456789”
将URL_A_chars设置为“$+!”/?;&@=#%>使用

因为
«class msng»
缺失值的原始AppleScript代码


显示对话框
命令显示该类的名称-->“msng”

谢谢,我是新手!
if theAnswer is missing value then
    display dialog "There was an error, you may have misspelled a word or phrased it incorrectly"
else
    display dialog theAnswer
end if