当我执行这个脚本时,一切正常,但是当我按下取消按钮时,脚本只给我一个错误,“无法获得 false 的第 1 项”
set mailList to {"Hide Applications", "Quit Applications", "Full Volume"}
set mailType to choose from list mailList
if item 1 of mailType is "Hide Applications" then
tell application "Finder"
set visible of every process whose visible is true and name is not "Finder" to false
set the collapsed of windows to true
end tell
else if item 1 of mailType is "Full Volume" then
set volume output volume 100
else if item 1 of mailType is "Quit Applications" then
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
end if
如果
mailType
是布尔值,则添加一个检查,如果您按取消,就会发生这种情况。支票将插入第 2 行和第 3 行之间,看起来像这样:
...
if class of mailType = boolean then return
...
choose from list
返回布尔值 false
当取消按钮被按下时。
在这种情况下立即中止脚本
set mailType to choose from list mailList
if mailType is false then return
如果 mailType 为 false 那么 显示带有图标注释按钮 {"Exit"} 默认按钮 {"Exit"} 的对话框“退出” 错误号 -128 结束如果
我的代码的语法不适合这个主题,所以下面是链接中的图片