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

AppleScript导出为.app时报错,此前运行正常求排查

AppleScript导出.app时的语法错误排查

你编写的AppleScript存在隐性语法错误,这是导致导出.app格式时触发异常的核心原因,具体问题和修正方案如下:

错误点分析

  1. 列表定义语法错误
    脚本第一行的列表末尾多了一个逗号和未闭合的引号:

    set modoption to {"Hold key for special characters", "Change \"Disk Almost Full\" notification threshold", "Install Brew", "}
    

    这个错误会打乱AppleScript解析器对代码结构的识别,进而引发后续一系列参数解析类报错。

  2. 报错关联逻辑
    第一次报错Expected “given”, “with”, “without”, other parameter name, etc. but found “mod”.,是因为列表未闭合,解析器误将choose from list命令里with prompt "Select mod:"中的mod判定为非法参数;修改prompt文本后,列表未闭合的根本问题仍存在,所以触发第二次报错Expected “,” or “}” but found identifier.。

修正后的完整脚本

set modoption to {"Hold key for special characters", "Change \"Disk Almost Full\" notification threshold", "Install Brew"}
set modoption to (choose from list modoption with prompt "Select mod:")

if modoption = {"Hold key for special characters"} then
    do shell script "defaults write -g ApplePressAndHoldEnabled -bool true"
else if modoption = {"Change \"Disk Almost Full\" notification threshold"} then
    display dialog "Disk Almost Full notification threshold" default answer "20"
    set notifsize to (text returned of result)
    do shell script "defaults write com.apple.diskspaced minFreeSpace " & notifsize
else if modoption = {"Install Brew"} then
    set brewinstallwarning to "This could take several hours."
    display dialog brewinstallwarning with icon caution
    do shell script "/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
end if

修正后重新导出.app格式即可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 06:30:54