【问题标题】:The equivalent of min(x,y) in AppleScript相当于 AppleScript 中的 min(x,y)
【发布时间】:2011-06-18 05:54:54
【问题描述】:

我有一个工作的 AppleScript,它有一个 repeat 看起来像这样:

repeat with i from 1 to count windows of proc
    ....
end repeat

现在我想把它改成 min(2,count windows of proc)

我将如何使用纯 AppleScript 编写此代码? (涉及 Bash 等的解决方案是不可接受的,问题实际上是关于如何从 AppleScript 执行此操作)

【问题讨论】:

    标签: macos applescript osascript


    【解决方案1】:

    没有内置的方法可以做到这一点。您必须自己编写函数:

    on min(x, y)
        if x ≤ y then
            return x
        else
            return y
        end if
    end min
    
    ...
    
    repeat with i from 1 to min(2, count windows of proc)
        ...
    end repeat
    

    请注意,如果您想在 tell ...using terms from ... 块内使用 min,则必须将其称为 my min(2, count windows of proc),以便 AppleScript 知道在脚本中查找 min,不在应用程序或你有什么的条款中。

    另外,请注意:您使用的语言称为 AppleScript,而不是 OsaScript。使用它的命令行工具称为osascript,因为它使用更通用的Open Scripting Architecture。其他语言(如 JavaScript)可以是 OSA 组件,但实际上,几乎每个人都使用 AppleScript。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-21
      • 2021-04-08
      • 2010-11-04
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 2012-06-18
      相关资源
      最近更新 更多