List AppleScript X包含在术语列表中
我认为只要使用“或”操作符,就可以检查变量“theMessage”是否包含“x”或“y”。显然不是 我试过这个:List AppleScript X包含在术语列表中,list,applescript,contains,List,Applescript,Contains,我认为只要使用“或”操作符,就可以检查变量“theMessage”是否包含“x”或“y”。显然不是 我试过这个: else if theMessage contains {"display", "screen"} then --sleep computer's display do shell script "pm displaysleepnow" set theResponse to "Now sleeping the computer's display" 我可能会写很多这样的东
else if theMessage contains {"display", "screen"} then
--sleep computer's display
do shell script "pm displaysleepnow"
set theResponse to "Now sleeping the computer's display"
我可能会写很多这样的东西,所以如果我能得到一个用操作符表示的子程序,那就太好了。。。e、 g
if theMessage contains {....} not {....}
你必须使用重复循环,类似这样的
on containsItems from qList against theText
repeat with anItem in qList
if theText contains anItem then return true
end repeat
return false
end containsItems
并使用它
set theMessage to "ashlfkjhalksjdhfscreenwperoivj"
set queryList to {"display", "screen"}
set doesContain to containsItems from queryList against theMessage
你必须使用重复循环,类似这样的
on containsItems from qList against theText
repeat with anItem in qList
if theText contains anItem then return true
end repeat
return false
end containsItems
并使用它
set theMessage to "ashlfkjhalksjdhfscreenwperoivj"
set queryList to {"display", "screen"}
set doesContain to containsItems from queryList against theMessage
这就是我不喜欢AppleScript的原因。这看起来不是太复杂了吗?所以每次我想比较多个东西,例如,包含x和y的消息,而不仅仅是x,我必须先将其设置为变量?为什么只使用一个术语就这么容易,但需要所有这些来比较两个或多个术语?是的,但处理程序会检查消息是否包含x或y。一个项目很容易,因为你选择1:1。对于多个项目,您必须选中1:这就是我不喜欢AppleScript的原因。这看起来不是太复杂了吗?所以每次我想比较多个东西,例如,包含x和y的消息,而不仅仅是x,我必须先将其设置为变量?为什么只使用一个术语就这么容易,但需要所有这些来比较两个或多个术语?是的,但处理程序会检查消息是否包含x或y。一个项目很容易,因为你选择1:1。对于多个项目,您必须检查1:n