AppleScript导出为.app时报错,此前运行正常求排查
AppleScript导出.app时的语法错误排查
你编写的AppleScript存在隐性语法错误,这是导致导出.app格式时触发异常的核心原因,具体问题和修正方案如下:
错误点分析
列表定义语法错误
脚本第一行的列表末尾多了一个逗号和未闭合的引号:set modoption to {"Hold key for special characters", "Change \"Disk Almost Full\" notification threshold", "Install Brew", "}这个错误会打乱AppleScript解析器对代码结构的识别,进而引发后续一系列参数解析类报错。
报错关联逻辑
第一次报错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
相关产品推荐
相关产品推荐

