开发者

The equivalent of min(x,y) in AppleScript

I've got a working AppleScript which has a repeat looking like this:

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

now I want to change this to开发者_开发问答 min(2,count windows of proc)

How would I write this using purely AppleScript? (solution involving Bash etc. are not acceptable, the question is really about how to do this from AppleScript)


There's no built-in way to do it. You'll have to write the function yourself:

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

Note that if you want to use min inside of a tell ... or using terms from ... block, you'll have to call it as my min(2, count windows of proc) so that AppleScript knows to look for min in the script, not in the terms from the application or what-have-you.

Also, a quick note: the language you're working with is called AppleScript, not OsaScript. The command-line tool for working with it is called osascript because it works with the more generic Open Scripting Architecture. Other languages (such as JavaScript) can be OSA components, but realistically speaking, pretty much everybody uses AppleScript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜