If statement 在if/else语句中设置变量?
我对applescript是个新手。我试图根据if条件更改变量的设置。用户选择一个时间,根据他们选择的时间,“时间”变量会发生变化。我得到错误“行尾不能在这个“”之后”,指的是“0”后面的引号,但我需要将这些数字设置为字符串值。我不确定我在这里缺少什么,因此非常感谢您的帮助If statement 在if/else语句中设置变量?,if-statement,applescript,If Statement,Applescript,我对applescript是个新手。我试图根据if条件更改变量的设置。用户选择一个时间,根据他们选择的时间,“时间”变量会发生变化。我得到错误“行尾不能在这个“”之后”,指的是“0”后面的引号,但我需要将这些数字设置为字符串值。我不确定我在这里缺少什么,因此非常感谢您的帮助 property time : "12" choose from list {"12 am", "1 am", "2 am", "3 am", "4 am", "5 am", "6 am", "7 am", "8 am",
property time : "12"
choose from list {"12 am", "1 am", "2 am", "3 am", "4 am", "5 am", "6 am", "7 am", "8 am", "9 am", "10 am", "11 am", "12 pm", "1 pm", "2 pm", "3 pm", "4 pm", "5 pm", "6 pm", "7 pm", "8 pm", "9 pm", "10 pm", "11 pm"} with title "Time Selection" with prompt "What time would you like?" OK button name "This Time" cancel button name "Cancel" default items {"12 am"}
if answer is equal to "12 am" then
set time equal to "0"
else if answer is equal to "1 am" then
set time equal to "1"
end if
有许多问题:
是保留字。不要将其用作变量time
是错误的语法,您必须将set…等于
set…写入
与答案
从列表中选择的结果不相关
- 即使前三个问题得到解决,
也会返回一个列表choose from list
property myTime : "12" set answer to choose from list {"12 am", "1 am", "2 am", "3 am", "4 am", "5 am", "6 am", "7 am", "8 am", "9 am", "10 am", "11 am", "12 pm", "1 pm", "2 pm", "3 pm", "4 pm", "5 pm", "6 pm", "7 pm", "8 pm", "9 pm", "10 pm", "11 pm"} with title "Time Selection" with prompt "What time would you like?" OK button name "This Time" cancel button name "Cancel" default items {"12 am"} if answer is false then return -- catch if nothing is selected set answer to item 1 of answer -- flatten the list if answer is equal to "12 am" then set myTime to "0" else if answer is equal to "1 am" then set myTime to "1" end if
set myResponse to choose from list {"12 am", "1 am", "2 am", "3 am", "4 am", "5 am", "6 am", "7 am", "8 am", "9 am", "10 am", "11 am", "12 pm", "1 pm", "2 pm", "3 pm", "4 pm", "5 pm", "6 pm", "7 pm", "8 pm", "9 pm", "10 pm", "11 pm"} with title "Time Selection" with prompt "What time would you like?" OK button name "This Time" cancel button name "Cancel" default items {"12 am"}
set UserChoice to item 1 of myResponse
set myTime to "" -- goods practice to initialise a variable
if UserChoice is "12 am" then
set myTime to "0"
else if UserChoice is "1 am" then
set myTime to "1"
end if
log myTime