Compare commits
No commits in common. "master" and "v1.5" have entirely different histories.
21
LICENSE.md
21
LICENSE.md
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 Santiago Lo Coco
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
24
cbattery
24
cbattery
|
@ -9,7 +9,6 @@ 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
|
||||||
|
@ -20,38 +19,31 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
write_cache() {
|
write_cache() {
|
||||||
[[ -n "$NO_CACHE" ]] || echo "$1" > "$TMP_FILE"
|
echo "$1" > "$TMP_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
read_cache() {
|
read_cache() {
|
||||||
cat "$TMP_FILE" 2> /dev/null
|
cat "$TMP_FILE" 2> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
log_message() {
|
|
||||||
timestamp=$(date "+%b %d %H:%M:%S")
|
|
||||||
echo "$timestamp - $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
enable_discharging() {
|
enable_discharging() {
|
||||||
log_message "Enabling battery discharging"
|
echo "Enabling battery discharging"
|
||||||
sudo smc -k CH0I -w 01
|
sudo smc -k CH0I -w 01
|
||||||
}
|
}
|
||||||
|
|
||||||
disable_discharging() {
|
disable_discharging() {
|
||||||
log_message "Disabling battery discharging"
|
echo "Disabling battery discharging"
|
||||||
sudo smc -k CH0I -w 00
|
sudo smc -k CH0I -w 00
|
||||||
}
|
}
|
||||||
|
|
||||||
enable_charging() {
|
enable_charging() {
|
||||||
[[ "$(get_smc_charging_hex)" == "00" ]] && return
|
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() {
|
||||||
[[ "$(get_smc_charging_hex)" != "00" ]] && return
|
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
|
||||||
}
|
}
|
||||||
|
@ -125,7 +117,7 @@ runScript() {
|
||||||
[[ -f "$launch_daemon" ]] && sudo launchctl unload -w "$launch_daemon"
|
[[ -f "$launch_daemon" ]] && sudo launchctl unload -w "$launch_daemon"
|
||||||
;;
|
;;
|
||||||
"charging")
|
"charging")
|
||||||
log_message "Setting $action to $setting"
|
echo "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" ;;
|
||||||
|
@ -133,7 +125,7 @@ runScript() {
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
"adapter")
|
"adapter")
|
||||||
log_message "Setting $action to $setting"
|
echo "Setting $action to $setting"
|
||||||
case "$setting" in
|
case "$setting" in
|
||||||
"on") enable_discharging ;;
|
"on") enable_discharging ;;
|
||||||
"off") disable_discharging ;;
|
"off") disable_discharging ;;
|
||||||
|
@ -143,7 +135,7 @@ runScript() {
|
||||||
"status")
|
"status")
|
||||||
case "$setting" in
|
case "$setting" in
|
||||||
"charging") exit "$(get_smc_charging_hex)" ;;
|
"charging") exit "$(get_smc_charging_hex)" ;;
|
||||||
"cache") get_cached_status ;;
|
"cache") echo "$(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
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/usr/local/bin/cbattery</string>
|
<string>/opt/homebrew/bin/cbattery</string>
|
||||||
<string>charging</string>
|
<string>charging</string>
|
||||||
<string>off</string>
|
<string>off</string>
|
||||||
</array>
|
</array>
|
||||||
|
@ -20,10 +20,5 @@
|
||||||
<key>StandardErrorPath</key>
|
<key>StandardErrorPath</key>
|
||||||
<string>/tmp/cbattery.stderr</string>
|
<string>/tmp/cbattery.stderr</string>
|
||||||
|
|
||||||
<key>EnvironmentVariables</key>
|
|
||||||
<dict>
|
|
||||||
<key>NO_CACHE</key>
|
|
||||||
<string>true</string>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|
Loading…
Reference in New Issue