Applescript 对话框中的对话框:第二个对话框不工作
我正试图编写一个脚本,使一个对话框询问“睡眠,重新启动,或关机”,当我选择“睡眠”选项时,会出现一个额外的对话框 重启和关机都能很好地工作,但是当我使用睡眠按钮,弹出额外的对话框时,它们就不工作了Applescript 对话框中的对话框:第二个对话框不工作,applescript,Applescript,我正试图编写一个脚本,使一个对话框询问“睡眠,重新启动,或关机”,当我选择“睡眠”选项时,会出现一个额外的对话框 重启和关机都能很好地工作,但是当我使用睡眠按钮,弹出额外的对话框时,它们就不工作了 set question to display dialog "Sleep, Restart, or Shutdown?" buttons {"Sleep", "Restart", "Shutdown"} with title "What do you want to do?" set answer
set question to display dialog "Sleep, Restart, or Shutdown?" buttons {"Sleep", "Restart", "Shutdown"} with title "What do you want to do?"
set answer to button returned of question
if answer is equal to "Restart" then
tell application "Finder" to restart
end if
if answer is equal to "Shutdown" then
tell application "Finder" to shutdown
end if
if answer is equal to "Sleep" then
display dialog "Exit All and Sleep or Just Sleep?" buttons {"Exit All", "Just Sleep"}
end if
if answer is equal to "Exit All" then
tell application "Finder" to run application "/Users/kjoesting/Desktop/Exit All and sleep.app"
else if answer is equal to "Just Sleep" then
tell application "Finder" to sleep
end if
问题是“全部退出并睡眠或只是睡眠”都不会做任何事情并返回:**告诉应用程序“AppleScript编辑器”
显示对话框“睡眠、重新启动或关机?”按钮{“睡眠”、“重新启动”、“关机”},标题为“您想做什么?”
-->{按钮返回:“睡眠”}
显示对话框“全部退出并睡眠还是仅睡眠?”按钮{“全部退出”、“仅睡眠”}
-->{按钮返回:“只需睡眠”}
结束通话**
有人能告诉我哪里出了问题吗?这样应该可以:
set question to display dialog "Sleep, Restart, or Shutdown?" buttons {"Sleep", "Restart", "Shutdown"} with title "What do you want to do?"
set answer to button returned of question
if answer is equal to "Restart" then
tell application "Finder" to restart
end if
if answer is equal to "Shutdown" then
tell application "Finder" to shut down
end if
if answer is equal to "Sleep" then
set question2 to display dialog "Exit All and Sleep or Just Sleep?" buttons {"Exit All", "Just Sleep"}
set answer2 to button returned of question2
if answer2 is equal to "Exit All" then
tell application "Finder" to run application "/Users/kjoesting/Desktop/Exit All and sleep.app"
else if answer2 is equal to "Just Sleep" then
tell application "Finder" to sleep
end if
end if
这是另一个版本。我对操作进行了注释,并添加了日志语句。 通过这种方式,您可以在不重新启动的情况下测试整个系统并查看其工作原理。取消对相关行的注释并删除日志语句,以使其在现实生活中正常工作:
display dialog "Sleep, Restart, or Shutdown?" buttons {"Sleep", "Restart", "Shutdown"} default button 1 with title "What do you want to do?"
set the button_pressed to the button returned of the result
if the button_pressed is "Sleep" then
-- action for 1st button goes here
log "Sleep"
display dialog "Exit All and Sleep or Just Sleep?" buttons {"Exit All", "Just Sleep"} default button 2
set the button_pressed to the button returned of the result
if the button_pressed is equal to "Exit All" then
--tell application "Finder" to run application "/Users/kjoesting/Desktop/Exit All and sleep.app"
log "Exit All"
else if button_pressed is equal to "Just Sleep" then
-- tell application "Finder" to sleep
log "Just Sleep"
end if
else if the button_pressed is "Restart" then
-- action for 2nd button goes here
log "Restart"
--tell application "Finder" to restart
else
-- action for 3rd button goes here (Shutdown)
log "Shut Down"
--tell application "Finder" to shut down
end if
顺便说一句:AppleScript编辑器有“代码片段”。按CTRL键进入脚本以查看它们。非常感谢!两个都很好!我有很多东西要学习,但我很享受使用它的经验。酷,txs的反馈。以下是“AppleScript语言指南简介”: