Last active
April 15, 2024 17:43
-
-
Save medeirosinacio/3a731921ab62b08b175ef782fe63eea7 to your computer and use it in GitHub Desktop.
MacOs Battery Alarm Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## display notification "Battery has disconnected with less than % battery" with title "Battery Alarm" | |
function debug() { | |
logger "$1" | |
echo "$1" | |
} | |
debug "CRONTAB | Battery Alarm Service Started" | |
charging_level=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1) | |
charging_status=$(pmset -g batt | awk '/Now drawing from/ {print $4}') | |
debug "CRONTAB | Current Battery Level: $charging_level%" | |
debug "CRONTAB | Current Battery Status: $charging_status" | |
if ! [ "$charging_status" == "'AC" ]; then | |
debug "CRONTAB | Battery is disconnected with $charging_level% battery" | |
osascript -e "display notification \"Battery is disconnected with $charging_level% battery\" with title \"Battery Alarm\"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instruções para agendar no crontab
Para agendar a execução do script no crontab, siga estas etapas:
crontab -e
para editar o crontab.<caminho_para_o_script>
pelo caminho absoluto do seu script.Isso irá agendar a execução do script para ser executado a cada minuto. Você pode ajustar a programação conforme necessário.
Como debugar
Para debugar a execução do script usando o comando
log
, siga estas etapas:log show --last 1m | grep CRONTAB