Macos AppleScript中min(x,y)的等价形式
我有一个正在工作的AppleScript,它有一个重复,看起来像这样:Macos AppleScript中min(x,y)的等价形式,macos,applescript,osascript,Macos,Applescript,Osascript,我有一个正在工作的AppleScript,它有一个重复,看起来像这样: repeat with i from 1 to count windows of proc .... end repeat 现在我想把它改为min(2,计算进程的窗口数) 我将如何使用纯AppleScript编写此文档?(涉及Bash等的解决方案是不可接受的,问题实际上是如何从AppleScript执行此操作)没有内置的方法。您必须自己编写函数: on min(x, y) if x ≤ y then
repeat with i from 1 to count windows of proc
....
end repeat
现在我想把它改为min(2,计算进程的窗口数)
我将如何使用纯AppleScript编写此文档?(涉及Bash等的解决方案是不可接受的,问题实际上是如何从AppleScript执行此操作)没有内置的方法。您必须自己编写函数:
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…
中使用min
或使用…
块中的术语,则必须将其称为my min(2,count windows of proc)
,以便AppleScript知道在脚本中查找min
,而不是在应用程序或您拥有的术语中查找
另外,请注意:您使用的语言称为AppleScript,而不是OsaScript。用于使用它的命令行工具称为
osascript
,因为它使用的是更通用的。其他语言(如JavaScript)可以是OSA组件,但实际上,几乎每个人都使用AppleScript。没有内置的方法来实现。您必须自己编写函数:
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…
中使用min
或使用…
块中的术语,则必须将其称为my min(2,count windows of proc)
,以便AppleScript知道在脚本中查找min
,而不是在应用程序或您拥有的术语中查找
另外,请注意:您使用的语言称为AppleScript,而不是OsaScript。用于使用它的命令行工具称为osascript
,因为它使用的是更通用的。其他语言(如JavaScript)可以是OSA组件,但实际上,几乎每个人都使用AppleScript