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

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

修复说明

  1. 移除了多余的双引号,解决语法报错
  2. 修正了拼写错误,让提示文本更规范
  3. 给每个弹窗的返回值设置了变量(firstAlertResult、secondAlertResult等),避免后续操作覆盖result变量导致逻辑错误
  4. 统一了Finder的大小写(AppleScript对应用程序名称大小写敏感,虽然部分情况不报错,但规范写法更稳妥)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 14:22:08