Read before writing smc
This commit is contained in:
parent
b54f0fbbfd
commit
0c58b2c27d
7
cbattery
7
cbattery
|
@ -9,6 +9,7 @@ PATH="/usr/bin:/usr/local/bin:/usr/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/op
|
||||||
usage() {
|
usage() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
usage: ${0##*/} [command]
|
usage: ${0##*/} [command]
|
||||||
|
|
||||||
charging [on|off] - Toggle charging
|
charging [on|off] - Toggle charging
|
||||||
adapter [on|off] - Toggle adapter connection
|
adapter [on|off] - Toggle adapter connection
|
||||||
status - Get status information
|
status - Get status information
|
||||||
|
@ -27,7 +28,7 @@ read_cache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
log_message() {
|
log_message() {
|
||||||
local timestamp=$(date "+%b %d %H:%M:%S")
|
timestamp=$(date "+%b %d %H:%M:%S")
|
||||||
echo "$timestamp - $1"
|
echo "$timestamp - $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +43,14 @@ disable_discharging() {
|
||||||
}
|
}
|
||||||
|
|
||||||
enable_charging() {
|
enable_charging() {
|
||||||
|
[[ "$(get_smc_charging_hex)" == "00" ]] && return
|
||||||
log_message "Enabling battery charging"
|
log_message "Enabling battery charging"
|
||||||
sudo smc -k CH0B -w 00
|
sudo smc -k CH0B -w 00
|
||||||
sudo smc -k CH0C -w 00
|
sudo smc -k CH0C -w 00
|
||||||
}
|
}
|
||||||
|
|
||||||
disable_charging() {
|
disable_charging() {
|
||||||
|
[[ "$(get_smc_charging_hex)" != "00" ]] && return
|
||||||
log_message "Disabling battery charging"
|
log_message "Disabling battery charging"
|
||||||
sudo smc -k CH0B -w 02
|
sudo smc -k CH0B -w 02
|
||||||
sudo smc -k CH0C -w 02
|
sudo smc -k CH0C -w 02
|
||||||
|
@ -140,7 +143,7 @@ runScript() {
|
||||||
"status")
|
"status")
|
||||||
case "$setting" in
|
case "$setting" in
|
||||||
"charging") exit "$(get_smc_charging_hex)" ;;
|
"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)" ;;
|
*) echo "Battery at $(get_battery_percentage)%, smc charging $(get_smc_charging_status)" ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in New Issue