如何使用applescript从特定电池百分比的电脑睡眠中自动醒来?

如何使用applescript从特定电池百分比的电脑睡眠中自动醒来?,applescript,Applescript,嘿,伙计们,我在这里绝对是新来的,在applescript上也是新来的。我正在使用apple脚本创建超级简单的通知自电池提醒。但问题是,我希望此通知能够在计算机睡眠期间自动唤醒。我使用咖啡因,但只对显示睡眠有效。任何一种想法或手册说明都可以解决这个问题 这是密码 set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable") tell Cap to set {wallPower} to {las

嘿,伙计们,我在这里绝对是新来的,在applescript上也是新来的。我正在使用apple脚本创建超级简单的通知自电池提醒。但问题是,我希望此通知能够在计算机睡眠期间自动唤醒。我使用咖啡因,但只对显示睡眠有效。任何一种想法或
手册
说明都可以解决这个问题

这是密码

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
set Cap to (do shell script "ioreg -wO -l | grep Capacity")
tell Cap to set {Available, Max} to {last word of paragraph 2, last word of paragraph 1}
set pct to round (100 * Available / Max)

if pct ≥ 95 then
    do shell script "caffeinate -u -t 1"
    tell application "iTunes" to play
    tell application "System Events"
        set volume 100
        display alert "Your macbook battery is 95%. recommended unplug it now"
        
    end tell
end if

else

set Cap to (do shell script "ioreg -wO -l | grep Capacity")
tell Cap to set {Available, Max} to {last word of paragraph 2, last word of paragraph 1}
set pct to round (100 * Available / Max)

if pct ≤ 30 then
    do shell script "caffeinate -u -t 1"
    tell application "iTunes" to play
    tell application "System Events"
        set volume 100
        display alert "Low battery, please plug in now"
        
    end tell
end if
end if
当我尝试
按键编码
按键
时,仍然不起作用
顺便说一句,很抱歉英语不好

在这篇评论中没有回答您的问题,只是一个改进编码的建议。如果您使用
将Cap设置为(do shell脚本“ioreg-wO-l”grep“\”Capacity\”=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\。然后你可以使用
将wallPower设置为Cap第3段的最后一个字
将{Available,Max}设置为{Cap第2段的最后一个字,第1段的最后一个字
另外,这是你正在尝试做的事情。谢谢你,但这里有一些错误,错误是“无法获得\”的第3段\\\“ExternalChargeable\\\”=No\\“ExternalChargeable\\”第3段中的编号-1728“您正在运行什么版本的macOS?如果我在macOS Catalina下的脚本编辑器中复制并粘贴我第一条评论中的链接处的代码,它将毫无问题地工作,SAN必须将iTunes更改为音乐,并使用
do shell Script
命令。因此,显然有一个
段落3
.10.11(El Capitan)和macbook 2010年年中
将Cap设置为什么(shell脚本“ioreg-wO-l | grep'\\\“Capacity\”=\\\\\\\\\\\\\\\\\\\\\\\\\\\ AppleRawCurrentCapacity\\\\\\\\\\\\\\\\\\\ ExternalChargeable'”
如果您自己运行它?