【问题标题】:AppleScript X is contained in list of termsAppleScript X 包含在术语列表中
【发布时间】:2017-05-23 12:53:40
【问题描述】:

我认为只需使用“or”运算符就可以检查变量“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"

我可能会写很多这样的东西,所以如果我能用运算符在 terms 中为 term 编写一个子例程,那就太好了...例如

if theMessage contains {....} not {....}

【问题讨论】:

    标签: list applescript contains


    【解决方案1】:

    你必须使用一个重复循环,像这样

    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 的原因。这看起来是不是太复杂了?
    • 所以每次我想比较不止一件事,例如theMessage 包含 x 和 y 而不仅仅是 x,我必须先将其设置为变量吗?为什么只有一个词这么容易,但比较两个或多个词就需要所有这些?
    • 是的,但是处理程序会检查 theMessage 是否包含 x y。一项很容易,因为您检查 1:1。对于多个项目,您必须检查 1:n
    猜你喜欢
    • 2017-03-25
    • 2011-01-15
    • 2015-09-24
    • 1970-01-01
    • 2016-03-29
    • 2011-02-11
    • 2022-01-13
    • 2014-10-01
    • 1970-01-01
    相关资源
    最近更新 更多