Open wild-a opened 4 weeks ago
I have the same issue. I installed with Homebrew cask on latest version of MacOS Sonoma
Ditto here with v1.2.2 installed via Homebrew on Sonoma 14.7 (23H124).
Dupe of #300.
Same issue on my side with Sequoia 15.1
Same. Everytime I restart the battery.app or reboot.
First it asks for permission, then gives a password prompt:
Then after it does it's thing, this is the confirmation message.
MacBook Pro | Apple M2 Max | Sonoma 14.6.1
If you're tired of entering your password every time the Battery app starts up, this script will configure your system to allow the Battery app to run without password prompts.
fix-battery.sh
chmod +x fix-battery.sh
sudo ./fix-battery.sh
#!/bin/bash
# Color codes for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get current user
CURRENT_USER=$(whoami)
if [ "$CURRENT_USER" = "root" ]; then
CURRENT_USER=$SUDO_USER
fi
# Logging function
log() {
echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"
}
error() {
echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] ERROR:${NC} $1"
}
success() {
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] SUCCESS:${NC} $1"
}
# Check if script is run as root
if [ "$EUID" -ne 0 ]; then
error "Please run this script with sudo"
exit 1
fi
# Print script start information
log "Starting battery sudo configuration script"
log "Configuring for user: $CURRENT_USER"
# Create backup of sudoers
log "Creating backup of sudoers configuration..."
if cp /etc/sudoers /etc/sudoers.backup; then
success "Backup created at /etc/sudoers.backup"
else
error "Failed to create sudoers backup"
exit 1
fi
# Create new sudoers file for battery app
log "Creating battery app sudoers configuration..."
cat > /etc/sudoers.d/battery-app << EOL
$CURRENT_USER ALL=(ALL) NOPASSWD: /usr/local/bin/smc -k CH0C -r
$CURRENT_USER ALL=(ALL) NOPASSWD: /usr/local/bin/smc -k CH0I -r
$CURRENT_USER ALL=(ALL) NOPASSWD: /usr/local/bin/smc -k ACLC -r
$CURRENT_USER ALL=(ALL) NOPASSWD: /usr/local/bin/smc -k ACLC -w 02
$CURRENT_USER ALL=(ALL) NOPASSWD: /usr/local/bin/battery
EOL
# Set correct permissions
log "Setting correct permissions..."
if chmod 440 /etc/sudoers.d/battery-app; then
success "Permissions set correctly"
else
error "Failed to set permissions"
rm /etc/sudoers.d/battery-app
exit 1
fi
# Validate sudoers syntax
log "Validating sudoers syntax..."
if visudo -c -f /etc/sudoers.d/battery-app; then
success "Sudoers syntax validated successfully"
else
error "Sudoers syntax validation failed"
rm /etc/sudoers.d/battery-app
exit 1
fi
# Test the configuration
log "Testing configuration with actual commands..."
# Test array of commands
declare -a test_commands=(
"/usr/local/bin/smc -k CH0C -r"
"/usr/local/bin/smc -k CH0I -r"
"/usr/local/bin/smc -k ACLC -r"
)
# Run tests
TEST_FAILED=0
for cmd in "${test_commands[@]}"; do
log "Testing command: $cmd"
if sudo -n $cmd &>/dev/null; then
success "Command executed without password: $cmd"
else
error "Failed to execute without password: $cmd"
TEST_FAILED=1
fi
done
if [ $TEST_FAILED -eq 0 ]; then
echo
echo -e "${GREEN}✅ Battery sudo configuration completed successfully${NC}"
echo -e "${GREEN}✅ All test commands executed without password prompts${NC}"
echo
log "You can now use the battery app without password prompts"
log "If you need to undo these changes, run: sudo rm /etc/sudoers.d/battery-app"
else
echo
error "Some tests failed. Configuration may not be complete."
error "Check the logs above for details"
echo
exit 1
fi
# Print final status check
echo
log "Final Configuration Status:"
echo "-------------------------"
echo "User configured: $CURRENT_USER"
echo "Sudoers file: /etc/sudoers.d/battery-app"
echo "Backup file: /etc/sudoers.backup"
echo "Syntax validation: Passed"
echo "Command tests: Passed"
echo "-------------------------"
If you need to remove these permissions, simply run:
sudo rm /etc/sudoers.d/battery-app
This script modifies system permissions to allow the Battery app to run specific commands without a password. While this is safe for the Battery app's specific commands, you should always be careful when modifying sudo permissions on your system.
The script includes several safety features:
What is the issue? (required) Battery requests to install a backwards incompatible update every time the app is started on MacOS Sequoia.
What exactly did you do to produce the issue? (required) Steps to reproduce the behavior:
Expected behavior (required) I expect battery to install that required item once and not again.
Screenshots (optional)