Code Monkey home page Code Monkey logo

charge-limiter's Introduction

Charge Limiter

macOS app to set battery charge limit for Intel MacBooks

Description

This app modifies a parameter called BCLM (presumably "Battery Charge Level Max") in the SMC which limits the charge of the battery to a set value. It also modifies a parameter called BFCL ("Battery Final Charge Level") which controls the MagSafe LED indicator light to display the correct status.

The source code can be viewed by opening src/Charge Limiter.app in Apple's Script Editor. It is written in Javascript Application Scripting (or JXA).

The companion bclm binary (located under src/Charge Limiter.app/Contents/Resources) was copied from this repository. The source code for bclm is also available there.

Releases

Download the latest version from the releases page.

Running

After setting a charge limit, the app will silently run and reapply the desired charge level again if you restart your Mac. If you wish to fully charge the battery again, set the charge limit to "100". This will also remove the charge limit persistency on boot. Afterwards, if you do not need the app anymore you can safely move it to the trash.

If you are running macOS High Sierra (10.13) or older, you may need to install Swift 5 Runtime Support.

Updates

This app will automatically check and notify you for any updates when you run it.

charge-limiter's People

Contributors

godly-devotion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

charge-limiter's Issues

Battery Showing 1% after 24hrs

mygregstuff@Router ~ % pmset -g batt Now drawing from 'AC Power' -InternalBattery-0 (id=5308515) 1%; AC attached; not charging (Poor/Good) failure: "Permanent Battery Failure" present: true

Charge indicator LED on Magsafe connector

While this software works brilliantly to limit the final charge on the battery, on my MacbookPro 11,1 the charge led on the magsafe connector always remains orange.

After a bit of a poke around on my machine the BFCL key sets the level at which the SMC turns the led green.
So to set the battery limit at 75%, BCLM=4b. If I set BFCL=4a then the battery charge led works correctly.

Hope this helps.

Thunderbolt / USBC port only receives power, Not data.

Hey! I have a macbook pro 2017 with two thunderbolt ports. A problem arose a few weeks ago after installing this code where only one port can receive data such as sound interface's via firewire to thunderbolt or a midi keyboard's USB2 to USBC. The lower (closest to my chest) port works as usual, but the upper one can only receive power. I'm thinking the faulty port doesn't receive enough power. I don't know for sure this problem is caused by the code but the problem arose when installing the code.

Prevent charger from charging battery on Mac M1

Is there a way to prevent the charger from charging the battery and to directly power the laptop instead using the terminal? I used to be able to do this one my intel Mac by blocking the middle pin. Is there a software / terminal command solution to this?

ChargeLimiter stops working on macOS Sierra after installing "Device Support Update"...

Previously was working. Recently performed a Software Update, and installed the Apple "Device Support Update" (I believe it was posted around Sept 2021, I just hadn't checked in a while).

Since then I receive this error upon launch;
The operation couldn’t be completed. (OSStatus error -192.)
(null) (-192)
Screen Shot 2022-03-25 at 7 14 48 pm

Previously I received this same error when attempting upgrade Charge Limiter from 1.4.1 to 1.5. Installing the Swift5 runtime package fixed it.
Unfortunately now, even after re-installing the Swift5 package, NONE of the versions I used to use work either! I've tried 1.3.1, 1.4.1, and 1.5. All with the same error.

Is there anything we can check to see what's causing this? Has Apple pulled the plug on running Swift utilities on macOS Sierra...?

Thank you.

error when setting value: any hardware limitations?

I've tried the script on a 2008 aluminum unibody Macbook running Sierra 10.12.6, but after entering a max charge value I get "There was an error setting the charge limit. Make sure you have administrator privileges." This is with the correct admin password.

This model doesn't officially support Sierra, but I have installed it with DOSDude's macOS Sierra Patcher Tool for Unsupported Macs. Just wondering if there might be a software workaround or it could be a hardware limitation.

Not working for Macbook Pro M2 Ventura 13.1

Is does not work for Macbook Pro M2.
I've tested in so many circumstances, but it always charges my laptop to 100%.

When I change the limiter, it does not show the limiter that I've put previously limiter on the app, the value is missing.
When I put back the limiter to 100%, I have an error message "make sure you have privilege access"
I do have root access of course and all the privilege that I need.

M2 Pro

Tried on Macbook M2 Pro base model and it didn't work.

Update deprecating python script

Hi, I found that charge-limiter is using python 2 to translate decimal to hex. You might want to update the python "to-hex" command to python 3 since Apple is deprecating python 2. I tried on my own machine and change it to python3 -c 'print("%02X" % ${value})' works. I am not making it a pull request because there are binaries inside and can have some code signing issues.

There was a problem setting the charge limit

So this app worked with no problems until now. Suddenly, it says "There was a problem setting the charge limit. Please make sure you have administrator privileges." and this is my own computer and I'm the admin... I own it... no problems... until now. For some reason I can't change the charge limit in v1.5.

Error with priviledges or M1 chip

Thanks for the app! It is exactly what I am looking for.

I am running it on macOS Big Sur with M1 CPU. The error message after entering admin password is: "There was a problem setting the charge limit. Please make sure you have administrator priviledge". It might be due to the M1 chip or priviledge ... I am not sure...

Resets after restart

Hi,

I've noticed that my laptop starts charging again after a reset, without my having to reset the SMC. Does this happen for anyone else?

Error - Symbol Not Found

Error on line 22: Error: dyld: Symbol not found: _$s17StringLiteralTypes013ExpressibleByaB0PTl
Referenced from: /Applications/Charge Limiter.app/Contents/Resources/bclm
Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
in /Applications/Charge Limiter.app/Contents/Resources/bclm (1005)

Error on MacOS El Capitan , MBP retina mid 2014 i7 3.1GHz

Why should I limit my laptop's charge?

You may see people suggesting you to limit your battery charge to 50%. Here I will go over why this is suggested.

NOTE: I in no way claim that the information presented below is accurate. I try to state my sources and reasonings and even go over what I am guessing on. Don't take my word for it; try to do your own research as well. Please feel free to add any more information. But at the end of the day, don't lose sleep over this.

Why would I want to limit my laptop's charge?

Apple says should be the charge batteries are stored at. If you are using your laptop off of AC power all the time, then you are effectively storing the battery, so this is a good charge to limit your battery to.

In reality you aren't "storing" the battery; the battery is still being somewhat used no matter what your charge is limited to. It's a necessity with how Macs (and presumably many other types of laptops) work. Some older laptops don't work this way I believe, but they may not have the same power requirements. Don't worry about this. This will happen and there's no way for you to stop it.

So, the battery is being perpetually used... does this mean limiting charge is useless? No. It's quite evident from the Battery University article that keeping a Li-ion battery at 50% perpetually is better than keeping it at 100% perpetually, by quite a long amount.

Limiting to 50% vs 80%

The common percentages to limit battery charge are 50% and 80%. 50% is the best because of reasons I can't really explain, but it has to do with it being some sort of middle ground for batteries. However, it's kind of inconvenient if you want to disconnect your laptop. That's why people usually opt for 80%, as this gives good lifetime. I'd suggest going with 80% for most people.

Limiting charge vs Apple's battery health management feature in Catalina

From my experience, Apple's management feature cycles the battery from 90-100% daily when it thinks that you won't be using your laptop on battery power. Is this better or worse than limiting your charge?

I strongly believe it's not as good as limiting your charge. Apple did this because of convenience. Think about it: the battery only goes to 90% for 5% of the day, when you're not using it on battery power anyway. This is much more convenient than limiting your maximum charge level, and that's why Apple chose to do it this way.

I believe that this helps your battery—I trust Apple's judgement here (and it would be kind of stupid to believe otherwise. Please no conspiracy theories, thanks). However, because of the above reason, I believe that this isn't as good as limiting your charge.

However, I would nonetheless recommend Apple's feature for the general user. That's why it's enabled by default on macOS 10.15.5+.

An argument against battery management: battery temperature and age are the biggest factors for battery degradation

If the temperature you store your battery at is bad, and your battery is old, both of these will likely have a greater effect on battery health than limiting your charge. This is why it's usually not worth it babying your battery and not enjoying it to its fullest—it will deteriorate anyway.

This is the argument that most anti-battery management people use on the internet. I can not 100% verify these claims; however, that does not mean that they are false—I just haven't looked into it that much.

Does it work on Linux?

Hi guys, I have an old MacBook Pro 7.1 running Ubuntu and I care to my battery lifespan. This project works on Linux? Do you guys know some that works?

cannot set charge limit to 100

when i tried to make it 100 it keep saying "There was a problem setting the charge limit. Please make sure you have administrator privileges." how do i fix it

Working on Late 2013 MacBook Pro

I just wanted to say thanks! I have it running on my Late 2013 15" MacBook Pro. I set it to 77% and plugged in my MacBook Pro which was discharged to 38%. The MacBook Pro charged to 80% and then stopped, so far so good! Thanks again!

Doesn't work with Catalina

I get the following display when opening the .dmg:
image

I even tried dragging the slashed out app to the Applications but the result was null.

I'm running the following system:
image

Different from aldente

While using aldente I noticed the magsafe light staying amber even when battery levels hit the limiter, whereas in this charge limiter the light turns to green.

What is the difference in functioning of these limiter softwares considering the aforementioned case?

Uninstall instructions

Would it be possible to add some instructions for uninstalling the app and reversing the changes it makes?
Or would resetting the SMC be required?

keyNotFound(code: "BCLM")%

When running the app, is says the current charge is "keyNotFound(code: "BCLM")%".

Even though it says success, the battery charge is not being limited.

I also get this message when running the command sudo /Applications/Charge\ Limiter.app/Contents/Resources/bclm write 80

I'm on an M1 MacBook Air running macOS Monterey 12.0.1

Patreon page or buy me a coffee page?

Hi @godly-devotion i would really thank you for this project!
I have an old mac air 2013 that works really well and i would like to use it most of the time as a xcode server without destroying the battery. This project it's the main part of my project!

Don't you have a patreon page or a buy me a coffee page? I would like to thank you!

Thank you so much, and sorry to bother you with this!

Path to smcutil hard coded

I saw your post over on the Al Dente issue and figured I'd give this a try, since I didn't understand exactly how you'd made it from your description. I tried to run it from my downloads folder and got this:

Screen Shot 2020-05-28 at 1 51 02 PM

Can't set 100% limit on m1 mac

Hallo! App does work on M1 Pro mac, but only once - it managed to set limit to 80%, but when I try to set it to 100% - it says "There was a problem setting the charge limit. Please make sure you have administrator privileges." How can I set 100% limit now? Maybe there is a terminal command?

*Optimized charging turned off

does not limit charging on MacBook Pro retina mid 2015

just installed this after replacing the battery.
Set max load to 80%. but the battery still is loaded over 80%. did a restart too.
the led on the charger is green, but in menu icon I see it is charging over 80%.
Any hints?

App still won't open

I did what you've said, but MacOs repeatedly told me to move it to the Bin. How open the app then?

Add simple test to warn if SwiftRuntimeForCommandLineTools.dmg is needed (like 10.14.3 or older). (feature request)

Maybe add warning inside app for those (like me) that did not read the Readme.md saying that SwiftRuntimeForCommandLineTools.dmg may be needed for macos 10.14.3 and earlier. (This app should run on macos 10.11, 10.12, and 10.13 high sierra, tho I think the Swift-runtime typically may only be needed for 10.12 or 10.13) In any case, I think we can check if Swift-runtime is needed by seeing if this file exists:

/usr/lib/swift/libswiftCore.dylib 

BTW... thanks for the app! The older macs running older macos with older batteries are the ones that really might be helped by this. I have seen quite a few with swollen batteries likely due to overheating/overcharging. (The darned Aldente app won't work on older macs as it requires 10.15 or newer ;-)

Anyways, when I added the snippet below to main.scpt it worked ok for me in some limited testing. YMMV ;-)

var app = Application.currentApplication()
app.includeStandardAdditions = true

// (snip) Test and warn if SwiftRuntimeForCommandLineTools.dmg is needed (like for 10.14.3 or earlier)
// See https://github.com/zackelia/bclm/issues/6
var path = Path('/usr/lib/swift/libswiftCore.dylib');
var finderApp = Application("Finder");
var status = finderApp.exists(path);
var url = `https://support.apple.com/kb/DL1998?locale=en_US`
// app.displayAlert(status)
if (status == false) {
	if (app.displayAlert(`For 10.14.3 and earlier please install SwiftRuntimeForCommandLineTools.dmg `, {
		message: `Please do small one-time-only install. Would you like to open the Apple download site?`,
		as: 'critical',
		buttons: ['Remind Me Later', 'Open site'],
		defaultButton: 'Open site'
	}).buttonReturned === 'Open site') {
		app.doShellScript(`open '${url}'`)
	}
}
// (\snip) End of test and warn if SwiftRuntimeForCommandLineTools.dmg is needed  

var version = 'v' + app.doShellScript(`defaults read '${app.pathTo(this)}/Contents/Info.plist' CFBundleShortVersionString`)
var latestVersion = app.doShellScript(`curl -s 'https://api.github.com/repos/godly-devotion/charge-limiter/releases/latest' | awk -F '"' '/tag_name/{print $4}'`)
var url = `https://github.com/godly-devotion/charge-limiter/releases/latest`

If anyone knows a better way than using Finder to test that file /usr/lib/swift/libswiftCore.dylib exists, then that might avoid possible issue where you might have to set finder to show all files. Tho in my quick and dirty testing, I do not think I had to do this:

   defaults write com.apple.Finder AppleShowAllFiles -bool YES

Macbook Pro 2017 unexpectedly restart

After installing this app and setting it to 75%, my Macbook Pro 2017 (macOS 10.14.6) began to restart itself when I'm not using it. I'm not sure if this is an issue people are also experiencing. I reset it to 100%. Let's see if it changes anything. Also please share with me if you have any advice. I'm really new here and do not really know what the codes are doing.

Charging percentages off

If I want to charge to 80% I need to instead set the limiter to 77%, otherwise it will go over 80.

It appears each charge % level requires guessing and trial and error to find out what to actually set the limiter to to hit the wanted target charge.

Error on line 22

On High Sierra 10.13.6 version 1.5 does not work. It just shows this error message:

Bildschirmfoto 2022-04-03 um 13 43 55
:

smcutil

Hello!

Could you please explain about "smcutil", what is it for?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.