You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AppleScript点击choose from list取消报“Can’t get item 1 of false”如何解决

AppleScript点击choose from list取消按钮报错解决方案

错误根因

choose from list 命令返回值存在两种情况:

  • 用户确认选中选项:返回包含选中内容的列表
  • 用户点击取消:返回布尔值 false
    原脚本未处理取消场景,默认mailType永远是列表,点击取消时执行item 1 of mailType就会触发取值错误。

修复方案

在获取mailType之后新增取消判断,用户点击取消时直接退出脚本即可,修改后的完整代码如下:

set mailList to {"Hide Applications", "Quit Applications", "Full Volume"}
set mailType to choose from list mailList

-- 新增取消判断:点取消直接终止脚本
if mailType is false then return

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

内容的提问来源于stack exchange,提问作者ABYSS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 06:54:04