AppleScript报错“Expected end of line but found identifier”求修复方案
AppleScript恶作剧脚本修复
你的脚本报错是因为语法错误,以下是问题点和修复后的完整代码:
问题分析
- 第8行末尾多了一个多余的双引号:
tell application "finder" to make new finder window",这直接导致解析器报错"Expected end of line but found identifier" - 存在拼写错误:
virusus应为viruses(不影响运行,但更符合英文规范) - 逻辑隐患:重复创建窗口后直接调用
result会丢失之前弹窗的返回值,需要提前存储弹窗结果
修复后的脚本
-- 初始弹窗 display alert "Finder can not check for viruses, continue?" buttons {"Cancel", "Continue"} default button 2 set firstAlertResult to button returned of the result if firstAlertResult is "Cancel" then tell application "Finder" to make new Finder window delay 1 tell application "Finder" to shut down else delay 2 -- 感染提示弹窗,存储结果 display alert "Your mac has been corrupted" buttons {"Abort", "Continue"} set secondAlertResult to button returned of the result -- 重复创建Finder窗口 repeat 10 times tell application "Finder" to make new Finder window end repeat if secondAlertResult is "Abort" then display alert "Viruses have control of your computer, you should remove them" buttons {"Remove"} default button 1 set thirdAlertResult to button returned of the result if thirdAlertResult is "Remove" then display alert "Your mac has been destroyed" end if else display alert "Your mac has been destroyed" delay 1 tell application "Finder" to shut down end if end if
修复说明
- 移除了多余的双引号,解决语法报错
- 修正了拼写错误,让提示文本更规范
- 给每个弹窗的返回值设置了变量(
firstAlertResult、secondAlertResult等),避免后续操作覆盖result变量导致逻辑错误 - 统一了
Finder的大小写(AppleScript对应用程序名称大小写敏感,虽然部分情况不报错,但规范写法更稳妥)
内容的提问来源于stack exchange,提问作者Jonathan Myron
相关产品推荐
相关产品推荐

