Applescript:未知的错误

问题描述:

我一直在研究脚本一段时间,并且提出了很多问题。根据一些人的建议我也重写了很多代码。然而,我仍然有这个问题没有答案。以下是iMessage PA的“Siri”代码。基本上,当我通过iMe​​ssage向它发送命令时,它会响应。Applescript:未知的错误

我一直在拼命地让它有更多的智慧,让它在句子中回复。你可以在代码中看到,当它问我“......你还好吗?”它应该寻找“是”或“否”,但只有当第一个问题被问到。但目前它只是响应最初的“我很好,先生,你还好吗?”然后当我说出是或否时,什么都不做。

只是为了确保它不是主代码,我添加了一个简单的“hello world”来查看它是否会正常响应。以下是代码:

using terms from application "Messages" 
    on message received theMessage from theBuddy for theChat 

     if theMessage is "hello" then 
      helloresponse() 
     end if 

     if theMessage contains "Are you ok" then 
      areyouok() 
      if theMessage is "yes" then 
       happyResponse() 
      else 
       if theMessage is "no" then 
        unhappyResponse() 
       end if 
      end if 
     end if 

     if theMessage contains "hello world" then 
      helloworldresponse() 
     end if 

    end message received 

end using terms from 

on helloresponse() 
    tell application "Messages" 
     send "Hey sir!" to buddy "[email protected]" of service "E:[email protected]" 
    end tell 
end helloresponse 

on happyResponse() 
    tell application "Messages" 
     send "you said yes, yey!" to buddy "[email protected]" of service "E:[email protected]" 
    end tell 
end happyResponse 

on unhappyResponce() 
    tell application "Messages" 
     send "You said no, thats a shame!" to buddy "[email protected]" of service "E:[email protected]" 
    end tell 
end unhappyResponce 

on areyouok() 
    tell application "Messages" 
     send "I am fine sir, are you ok?" to buddy "[email protected]" of service "E:[email protected]" 
    end tell 
end areyouok 

on helloworldresponse() 
    tell application "Messages" 
     send "World replies: Hello." to buddy "[email protected]" of service "E:[email protected]" 
    end tell 
end helloworldresponse 

感谢任何帮助的人可以给我!

+0

我已经更新我的答案给你如何Ÿ一个想法响应你可以测试你的逻辑,也可以看到获得你想要的答案的方法 – markhunte 2013-05-07 23:39:46

如果我正在阅读此权利。

你会得到一个消息,“你还好吗”

剧本的反应是“我很好,先生,你还好吗?”

你得到一个消息发回“是”或“否”

但这种情况正在等待“是”或“否”的消息被埋没了,如果块中的“我很好脚本的一部分先生,你还好吗?“所以它永远不会被触发。

**更新

这是一种测试您的逻辑的方法。

创建两个脚本。

第一个将是逻辑的一个。你将在Applescript编辑器中运行它。

property lastMessage : "" 

set theMessage to load script "/PATH/TO/SECOND/SCRIPT/secondScript.scpt" 
run theMessage 

if theMessage is "hello" then 
    helloresponse() 
end if 

if theMessage contains "Are you ok" then 

    areyouok() 

end if 

if theMessage is "yes" and lastMessage is "I am fine sir, are you ok?" then 
    happyResponse() 
else if theMessage is "no" and lastMessage is "I am fine sir, are you ok?" then 
    unhappyResponse() 

end if 


if theMessage contains "hello world" then 
    helloworldresponse() 
end if 




on helloresponse() 
    say "Hey sir!" 
end helloresponse 

on happyResponse() 
    say "you said yes, yey!" 
    set lastMessage to "" 
end happyResponse 

on unhappyResponce() 
    say "You said no, thats a shame!" 
    set lastMessage to "" 
end unhappyResponce 

on areyouok() 
    say "I am fine sir, are you ok?" 
    set lastMessage to "I am fine sir, are you ok?" 
end areyouok 

on helloworldresponse() 
    say "World replies: Hello." 
end helloworldresponse 

。注意到财产我已经给它的。传递给属性的任何变量都存储在那里。并且可以在脚本稍后再次运行时访问。

在这种情况下,我已经将它设置为存储最后的回复/消息,如果回复是“我很好,先生,你还好吗?”

我也拆你的如果块,这样的happyResponse和unhappyResponse响应将只用“是”或“否”的消息被触发,只要存储在属性lastMessage最后的反应是“我好的先生,你还好吗?“

在第一个脚本中是一行加载和运行第二个脚本。

第二个脚本用于给出消息。该脚本被编辑并保存。

例如第二个脚本将只包含;

set theMessage to "Are you ok" 

第二个脚本被保存。 然后你运行第一个脚本来获取它的消息并作出回应。 这应该是“我很好,先生,你还好吗

然后就可以编辑和保存第二个脚本;

set theMessage to "yes" 

,并再次运行第一个脚本的反应应该是。 “你说的没错,yey!”

你会得到你期待