Add log function

This commit is contained in:
Santiago Lo Coco 2024-04-10 13:58:21 +02:00
parent 9204bc1c07
commit b54f0fbbfd
1 changed files with 11 additions and 6 deletions

View File

@ -26,24 +26,29 @@ read_cache() {
cat "$TMP_FILE" 2> /dev/null cat "$TMP_FILE" 2> /dev/null
} }
log_message() {
local timestamp=$(date "+%b %d %H:%M:%S")
echo "$timestamp - $1"
}
enable_discharging() { enable_discharging() {
echo "Enabling battery discharging" log_message "Enabling battery discharging"
sudo smc -k CH0I -w 01 sudo smc -k CH0I -w 01
} }
disable_discharging() { disable_discharging() {
echo "Disabling battery discharging" log_message "Disabling battery discharging"
sudo smc -k CH0I -w 00 sudo smc -k CH0I -w 00
} }
enable_charging() { enable_charging() {
echo "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() {
echo "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
} }
@ -117,7 +122,7 @@ runScript() {
[[ -f "$launch_daemon" ]] && sudo launchctl unload -w "$launch_daemon" [[ -f "$launch_daemon" ]] && sudo launchctl unload -w "$launch_daemon"
;; ;;
"charging") "charging")
echo "Setting $action to $setting" log_message "Setting $action to $setting"
case "$setting" in case "$setting" in
"on") enable_charging && write_cache "enabled" ;; "on") enable_charging && write_cache "enabled" ;;
"off") disable_charging && write_cache "disabled" ;; "off") disable_charging && write_cache "disabled" ;;
@ -125,7 +130,7 @@ runScript() {
esac esac
;; ;;
"adapter") "adapter")
echo "Setting $action to $setting" log_message "Setting $action to $setting"
case "$setting" in case "$setting" in
"on") enable_discharging ;; "on") enable_discharging ;;
"off") disable_discharging ;; "off") disable_discharging ;;