
Step1
首先開啟文字編輯器,輸入下方的語法,並儲存為batteryScript.applescript,而這邊梅干是設定當電量小於15%時,就跳提示窗,這數值可自行修改。
batteryScript.applescript語法:
set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable")
tell Cap to set {wallPower} to {last word of paragraph 1}
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 percent to round (100 * Available / Max)
if percent <= 15 then
# cargar
tell application "Finder"
activate
set dialog_text to "電力只剩於 " & percent & "%. 請接上電源供應器"
display dialog dialog_text
end tell
end if |
Step2
將它移到/etc/資料夾下。
Step3
再輸入電腦管理的帳號密碼。
Step4
接著開啟終端機,並輸入下方的指令。
sudo chmod +rx /etc/batteryScript.applescript
Step5
接著再開啟文字編輯器,輸入下方的語法,並儲存為batteryAlert.plist。
batteryAlert.plist語法:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <false/> <key>Label</key> <string>batteryAlert</string> <key>LowPriorityIO</key> <true/> <key>ProgramArguments</key> <array> <string>/usr/bin/osascript</string> <string>/etc/batteryScript.applescript</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceDescription</key> <string>Battery Alert</string> <key>StartInterval</key> <integer>30</integer> </dict> </plist> |
Step6
接著進入帳號 / 資源庫。
Step7
將剛儲存好的batteryAlert.plist檔案,放到LaunchAgents資料夾下。
Step8
接著當電量小於15%時,就會跳出提示窗。