AppleScript小于或大于数字

时间:2014-01-10 02:49:45

标签: applescript

当我连续使用小于或大于运算符时,我在AppleScript中出错。我可能没有解释得那么好,所以我会发布代码。

**set good to false**

**repeat until good = true**
set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number

if oneTen is less than 0 then
    display dialog "below" buttons {""} default button 1
else if oneTen is greater than 10 then
    display dialog "above" buttons {""} default button 1
else
    set good to true
end if
**end repeat**

我正在尝试从提示中获取输入,并阻止用户输入低于0或高于10的任何内容。您可以发布一些代码来做到这一点吗?

我想要类似的东西。

**set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number**

**if oneTen is less than 0 or greater than 10 then**

**-- make them do the prompt again**

**end if**

1 个答案:

答案 0 :(得分:2)

尝试:

repeat
    set oneTen to the text returned of (display dialog "Pick a number from 1 through 10" default answer "" buttons {"OK"} default button 1) as number

    if oneTen is less than 0 then
        display dialog "below" buttons {""} default button 1
    else if oneTen is greater than 10 then
        display dialog "above" buttons {""} default button 1
    else
        exit repeat
    end if
end repeat