Skip to content

Instantly share code, notes, and snippets.

@powext
Created January 3, 2024 22:15
Show Gist options
  • Save powext/269251694348e82f538123ed8bd67107 to your computer and use it in GitHub Desktop.
Save powext/269251694348e82f538123ed8bd67107 to your computer and use it in GitHub Desktop.
RayCast script to limit macbook charging until 80% through actuallymentor/battery CLI
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Battery - Limit Charging to 80%
# @raycast.mode compact
# Optional parameters:
# @raycast.icon 🤖
# Documentation:
# @raycast.author Simone Bianchin
for job in $(jobs -p | grep 'battery discharge' | awk '{print $3}')
do
echo "Killing job $job"
kill $job
done
# Fetch the battery status
battery_output=$(battery status)
battery_percentage=$(echo "$battery_output" | awk -F' - ' '/Battery at/{split($2,a," "); print a[3]}' | tr -d '%,')
if [ "$battery_percentage" -gt 80 ]; then
battery discharge 80 > /dev/null 2>&1 &
else
battery maintain 80
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment