Quantcast
Viewing all articles
Browse latest Browse all 2929

《Macbook 優勝美地》低電量時跳出提示視窗

Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗
  印象中之前在使用MAC OSX10.9版,當Macbook電量太低時,除了電池圖示會變色外,還會跳出提醒視窗,但升級到MAC新版的作業系統優勝美地後,不但電池不會變色外,就連提示視窗也沒有,讓梅干感到相當困擾,每次當認真做事時,忘了留意電量,電腦就無預警的休眠,上網爬些文章後,終於找到了解決辦法,只要寫點script立即就可開啟此功能,經梅干實測後,即便在Parallel底下,當低電量時,依然也會跳出提示框來,因此若你也有這困 擾的朋友,也一塊來看看吧!
Step1
首先開啟文字編輯器,輸入下方的語法,並儲存為batteryScript.applescript,而這邊梅干是設定當電量小於15%時,就跳提示窗,這數值可自行修改。

batteryScript.applescript語法:
?View Code SCRIPT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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

Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Step2
將它移到/etc/資料夾下。
Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Step3
再輸入電腦管理的帳號密碼。
Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Step4
接著開啟終端機,並輸入下方的指令。
sudo chmod +rx /etc/batteryScript.applescript

Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Step5
接著再開啟文字編輯器,輸入下方的語法,並儲存為batteryAlert.plist
batteryAlert.plist語法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?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>

Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Step6
接著進入帳號 / 資源庫
Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Step7
將剛儲存好的batteryAlert.plist檔案,放到LaunchAgents資料夾下。
Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Step8
接著當電量小於15%時,就會跳出提示窗。
Image may be NSFW.
Clik here to view.
梅問題-《Macbook優勝美地》低電量時跳出提示視窗

Viewing all articles
Browse latest Browse all 2929

Trending Articles