我怎样才能使控制的iMessage回复不同的AppleScript? [英] How can I make an applescript controlled iMessage reply differently?
问题描述
我一直在编码的AppleScript我贾维斯自己的版本了几天,现在,我一直在使用iMessage讯息作为我的输入和输出,因为我爱的方式的便携,但我现在想获得一点更先进,更开始使得它感觉像它有一个使用。
I have been coding my own version of Jarvis in Applescript for a few days now, I have been using iMessages as my input and output as I love the way its portable, yet I now want to get a bit more advanced and start making it feel like it has a use.
目前我只使用code的简单的线条承认,当我送点东西,然后运行相应的脚本发送回复。比如,如果我说你好,它说:你好先生回到我身边。
Currently I just use simple lines of code to recognise when I send something and then run the appropriate script to send a reply. Such as, If I say "hello", it says "hello sir" back to me.
一个例子是:
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
if theMessage is "hello" then
run script ("/Users/Alex/Desktop/JarvisScripts/hello.scpt" as POSIX file)
end if
end message received
end using terms from
都好,但是我前面说过我想走得更远,我需要一种方式,它可以问我一个问题,如你好吗,然后根据不同我说什么回来,如好吧将运行脚本正确回应好。
All good, but I as I said before I want to go further, I need a way it can ask me a question such as "how are you", and then depending on what I say back such as "good" it will run the right scripts to respond to "good". My current attempts go along the lines of:
if theMessage contains "Are you ok" then
run script ("/Users/Alex/Desktop/JarvisScripts/areyouok.scpt" as POSIX file)
if theMessage is "I'm fine" then
run script ("/Users/Alex/Desktop/JarvisScripts/happy.scpt" as POSIX file)
else
if theMessage is "No I'm not" then
run script ("/Users/Alex/Desktop/JarvisScripts/unhappy.scpt" as POSIX file)
end if
end if
end if
但我知道这是远离正确的。因此,任何人可以帮助我做一些code?谢谢
But I know this is far from correct. So, can anybody help me with some code? Thanks
推荐答案
而不是在单独的脚本文件存储你的反应'的。尝试使用,而不是处理程序
Instead of storing your 'responses' in separate script files. Try using a handler instead.
例如:
if theMessage contains "Are you ok" then
run script ("/Users/Alex/Desktop/JarvisScripts/areyouok.scpt" as POSIX file)
if theMessage is "I'm fine" then
happyResponse()
else
if theMessage is "No I'm not" then
unhappyResponse()
end if
end if
end if
--HANDLERS--
on unhappyResponse()
--<<whatever you want to happen (the code inside your .scpt file)>>
end unhappyResponse
on happyResponse()
--<<put the contents of happy.scpt here>>
end happyResponse
正如你所看到的'处理'是在你的code的底上市时的功能之一是所谓的,code是他们的评价。现在,我不知道你是什么.scpt文件里面,但这在大多数应用工作。
As you can see, the 'handlers' are listed at the bottom of your code and whenever one of the functions are called, code is evaluated for them. Now I don't know what is inside of your .scpt files but this should work in most uses.
这篇关于我怎样才能使控制的iMessage回复不同的AppleScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!