2011-01-30 123 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。