2011-01-30 40 views
1

等效我有一个工作OsaScript具有重复看起来像这样:分钟(X,Y)的OsaScript

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

现在我要改变这分钟(2,计数窗口的proc)

我会如何使用纯粹的OsaScript写这个? (涉及Bash等的解决方案是不可接受的,但问题实际上是关于如何从OsaScript执行此操作)

回答

3

没有内置的方法来执行此操作。你必须自己编写的函数:

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 

请注意,如果你想使用一个mintell ...using terms from ...里面,你必须称呼其为my min(2, count windows of proc),这样的AppleScript知道如何寻找min在脚本中,而不是来自应用程序或您拥有的东西。

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