Skip to content

How to Extend MacBook Battery Life

Importance of Proper MacBook Battery Charging

Before we dive into creating the script, let’s discuss why it’s important to manage your MacBook’s battery charging correctly. Most laptop batteries use lithium-ion (Li-ion) technology, which has a limited number of charge-discharge cycles. Proper charging management helps extend the battery’s lifespan and maintain its performance.

Here are two main rules:

  1. Avoid deep discharges: Consistently discharging below 20% can negatively impact the battery’s health and shorten its lifespan.

  2. Avoid constant charging to 100%: Constantly charging to full capacity can also reduce the battery’s lifespan.

Step 1: Creating the Script

We will use AppleScript to create a script that will regulate the battery charging process according to set thresholds. Here is an example of such a script:

  1. Open the “Script Editor” on your MacBook. (You can use Command + Space to search)
    Open Script Editor

  2. Create a “New Document”
    Create New Document

  3. Paste the following AppleScript code:

property lowBatteryThreshold : 20 -- Low battery threshold
property highBatteryThreshold : 80 -- High battery threshold
property checkFrequency : 300 -- Check frequency in seconds (5 minutes)
on run
checkBattery()
end run
on idle
delay checkFrequency -- Check every 5 minutes
checkBattery()
return checkFrequency
end idle
on checkBattery()
set batteryPercentage to do shell script "pmset -g batt | grep -o '\\d\\+%' | sed 's/%//'"
if batteryPercentage as number lowBatteryThreshold then
display notification "Please connect the charger. Battery level is below " & lowBatteryThreshold & "%."
end if
if batteryPercentage as number highBatteryThreshold then
display notification "Please disconnect the charger. Battery level is above " & highBatteryThreshold & "%."
end if
end checkBattery
  1. Save the script
    Save Script

  2. Choose the format “Application”, and check “Stay open after running handler”
    Save As Application

This script will check the battery status every 5 minutes and send notifications if the charge level exceeds or falls below the set thresholds.

Step 2: Adding the Script to Startup Items

  1. Open “System Preferences” on your MacBook.
    System Preferences

  2. Select “General”.

  3. Choose “Login Items”.
    Login Items

  4. Click the ”+” button.
    Add Login Item

  5. Select the saved script from the file system.
    Select Script

Now the script will automatically run at login, optimizing your MacBook’s battery charging.

Conclusion

With this script, you can optimize your MacBook’s battery charging process, increasing its lifespan and ensuring your device operates for longer throughout the day. Remember, proper charging management is a key aspect of maintaining your MacBook’s long-term performance.