首页 > 解决方案 > 第一个 MacOS Apple 脚本:它可以工作,但不能关闭盖子

问题描述

我使用脚本编辑器完成了我的第一个 Apple 脚本。目的是在满足某些条件时说出文本。打开盖子工作得很好。

脚本在带有 Catalina 10.15.7 的 MacBook Pro 2013 年末运行。脚本也适用于:MacBook Air M1 Late 2020 w/Big Sur 11.3(尚未实施)

问题:合上盖子时脚本不会朗读文本。有没有办法让它在盖子关闭时继续运行(并说出文本)?

这是脚本(简短版),尽管它与问题无关:

set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable")

tell Cap to set {wallPower} to {last word of paragraph 1}
if wallPower = "Yes" then
    return 0
else
    set Pct to (do shell script "pmset -g batt | grep -Eo \"\\d+%\" | cut -d% -f1")
    if Pct ≤ 10 then
        display notification "Batterij 10%. Meteen opladen." with title "Batterij bijna leeg!" sound name "Sosumi"
        ##      delay 300
        ## say "Batterij 10%. Meteen opladen."
    end if
end if 

谢谢!皮特

标签: macosapplescript

解决方案


推荐阅读