diff --git a/cbattery b/cbattery index 9ec34ea..3973d37 100755 --- a/cbattery +++ b/cbattery @@ -9,6 +9,7 @@ PATH="/usr/bin:/usr/local/bin:/usr/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/op usage() { cat << EOF usage: ${0##*/} [command] + charging [on|off] - Toggle charging adapter [on|off] - Toggle adapter connection status - Get status information @@ -27,7 +28,7 @@ read_cache() { } log_message() { - local timestamp=$(date "+%b %d %H:%M:%S") + timestamp=$(date "+%b %d %H:%M:%S") echo "$timestamp - $1" } @@ -42,12 +43,14 @@ disable_discharging() { } enable_charging() { + [[ "$(get_smc_charging_hex)" == "00" ]] && return log_message "Enabling battery charging" sudo smc -k CH0B -w 00 sudo smc -k CH0C -w 00 } disable_charging() { + [[ "$(get_smc_charging_hex)" != "00" ]] && return log_message "Disabling battery charging" sudo smc -k CH0B -w 02 sudo smc -k CH0C -w 02 @@ -140,7 +143,7 @@ runScript() { "status") case "$setting" in "charging") exit "$(get_smc_charging_hex)" ;; - "cache") echo "$(get_cached_status)" ;; + "cache") get_cached_status ;; *) echo "Battery at $(get_battery_percentage)%, smc charging $(get_smc_charging_status)" ;; esac ;;