From 8761f97a0e5778b0b3f93f7de153a95950203b20 Mon Sep 17 00:00:00 2001 From: base47 Date: Wed, 19 Nov 2025 22:00:39 +0100 Subject: [PATCH 1/3] Fix force discharge option for users using a shell other than zsh. --- battery.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/battery.sh b/battery.sh index 1b1d7fb..aa0066a 100755 --- a/battery.sh +++ b/battery.sh @@ -667,9 +667,9 @@ if [[ "$action" == "maintain_synchronous" ]]; then fi # Parse setting - could be single value or range - local lower_bound="" - local upper_bound="" - local is_range=false + lower_bound="" + upper_bound="" + is_range=false if valid_percentage_range "$setting"; then # Range format: lower-upper @@ -689,7 +689,7 @@ if [[ "$action" == "maintain_synchronous" ]]; then # Check if the user requested that the battery maintenance first discharge to the desired level if [[ "$subsetting" == "--force-discharge" ]]; then # Before we start maintaining the battery level, first discharge to the target level - local discharge_target="$lower_bound" + discharge_target="$lower_bound" log "Triggering discharge to $discharge_target before enabling charging limiter" $battery_binary discharge "$discharge_target" log "Discharge pre battery-maintenance complete, continuing to battery maintenance loop" From 8f63a7b9be295c034bcd03c8e7fe66df3d40ad9c Mon Sep 17 00:00:00 2001 From: base47 Date: Wed, 19 Nov 2025 23:24:43 +0100 Subject: [PATCH 2/3] Fix the visudo_complete check and avoid writing the SMC key CH0J, which is supposedly never written by battery.sh --- app/modules/battery.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/modules/battery.js b/app/modules/battery.js index aa6ba2b..742eb05 100644 --- a/app/modules/battery.js +++ b/app/modules/battery.js @@ -139,10 +139,10 @@ const initialize_battery = async () => { '-k CH0C -r', '-k CH0I -r', '-k ACLC -r', - '-k ACLC -w 02', - // Update for Sanoma 26.x + // Apple introduced the following two in 2025. + // It seems to apply to all Apple Silicon MacBooks, regardless of macOS version. '-k CHTE -r', - '-k CH0J -w 01' + '-k CHIE -r' ] const [ battery_installed, @@ -150,21 +150,23 @@ const initialize_battery = async () => { charging_in_visudo, discharging_in_visudo, magsafe_led_in_visudo, - additional_magsafe_led_in_visudo + chte_charging_in_visudo, + chie_discharging_in_visudo, ] = await Promise.all( [ exec_async( `${ path_fix } which battery` ).catch( low_err_return_false ), exec_async( `${ path_fix } which smc` ).catch( low_err_return_false ), ...smc_commands.map( cmd => exec_async( `${ path_fix } sudo -n /usr/local/bin/smc ${ cmd }` ).catch( low_err_return_false ) ) ] ) - const visudo_complete = ![ charging_in_visudo, discharging_in_visudo, magsafe_led_in_visudo, additional_magsafe_led_in_visudo ].some( entry => entry === false ) + const visudo_complete = ![ charging_in_visudo, discharging_in_visudo, magsafe_led_in_visudo, chte_charging_in_visudo, chie_discharging_in_visudo ].some( entry => entry === false ) const is_installed = battery_installed && smc_installed log( 'Is installed? ', is_installed ) log( 'Visudo complete? ', { charging_in_visudo, discharging_in_visudo, magsafe_led_in_visudo, - additional_magsafe_led_in_visudo, + chte_charging_in_visudo, + chie_discharging_in_visudo, visudo_complete } ) From 232559e06cd1b452c73bf06d4ef9aea03bf26fca Mon Sep 17 00:00:00 2001 From: base47 Date: Thu, 20 Nov 2025 01:15:25 +0100 Subject: [PATCH 3/3] Do not invoke battery visudo from update.sh, because it may crash the UI (issue #377) --- battery.sh | 8 ++++++++ update.sh | 5 +---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/battery.sh b/battery.sh index aa0066a..570ce19 100755 --- a/battery.sh +++ b/battery.sh @@ -509,6 +509,14 @@ if [[ "$action" == "update" ]]; then read fi curl -sS https://raw.githubusercontent.com/actuallymentor/battery/main/update.sh | bash + if [[ ! "$setting" == "silent" ]]; then + # The setting "silent" is always passed when `battery update` is invoked from the UI app, + # which decides whether to invoke `battery visudo` as well. But for Terminal-only users + # there is no UI app. So it's either we invoke `battery visudo` here, or assume that users + # remember to do it themselves, which did not work in the past. + echo "Runnig $battery_binary visudo" + $battery_binary visudo + fi fi exit 0 fi diff --git a/update.sh b/update.sh index cca1f3b..fb13c58 100644 --- a/update.sh +++ b/update.sh @@ -24,12 +24,9 @@ chown $USER $binfolder/battery chmod 755 $binfolder/battery chmod u+x $binfolder/battery -echo "[ 3 ] Updating visudo declarations" -$binfolder/battery visudo - # Remove tempfiles cd rm -rf $tempfolder -echo "[ 4 ] Removed temporary folder" +echo "[ 3 ] Removed temporary folder" echo -e "\nšŸŽ‰ Battery tool updated.\n"