我正在编写一个脚本,该脚本向y个人发送x消息x消息。但是,我的主要问题是提示用户输入x,y和z。这是我的基本代码。
on run
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy "18008888888" of targetService
repeat 3 times
send " beef bowl " to targetBuddy
end repeat
end tell
end run
如您所见,它将3次将消息“牛肉碗”发送到18008888888。但是,当我添加提示时,它会破坏代码。
set numberTo to display dialog "What is the number?" default answer ""
...
set targetBuddy to buddy numberTo of targetService
我的代码有什么问题? 谢谢!
答案 0 :(得分:0)
repeat
try
set theResult to text returned of (display dialog "blabla" default answer "" buttons {"OK"} default button "OK")
set numberTo to (theResult as integer)
exit repeat
on error
-- You may show a warning here to enter a number
end try
end repeat
使用重复循环在输入错误时再次显示对话框。 使用try块检查强制(作为整数)。