下面是一个使用AppleScript实现用户交互的示例代码:
-- 获取用户输入
set userInput to text returned of (display dialog "请输入你的名字:" default answer "")
-- 显示带有用户输入的提示框
display dialog "你好," & userInput & "!欢迎使用AppleScript。"
-- 显示选择框并根据用户选择执行不同的操作
set userChoice to button returned of (display dialog "请选择一个操作:" buttons {"操作1", "操作2", "取消"} default button "取消")
if userChoice is "操作1" then
display alert "你选择了操作1。"
else if userChoice is "操作2" then
display alert "你选择了操作2。"
else
display alert "你取消了操作。"
end if
这个示例代码首先使用display dialog
命令获取用户的输入,并将其保存在变量userInput
中。然后,使用display dialog
命令显示一个带有用户输入的提示框。最后,使用display dialog
命令显示一个选择框,并根据用户的选择执行不同的操作。
你可以根据需要修改代码中的提示文本和操作,以实现你想要的用户交互功能。