O script abaixo usa duas chamadas para dbus
e um loop para pesquisar a porcentagem. Configuração muito simples e eficaz. Execute isto quando quiser desligar o laptop assim que ele for carregado
#!/bin/bash
get_percentage()
{
qdbus org.gnome.SettingsDaemon.Power \
/org/gnome/SettingsDaemon/Power \
org.gnome.SettingsDaemon.Power.Percentage
}
shutdown_system()
{
qdbus com.canonical.Unity \
/com/canonical/Unity/Session \
com.canonical.Unity.Session.Shutdown
}
# Basically loop that waits till
# battery reaches 100%. When 100%
# reached , loop exits, and next command
# is executed, which is shutdown
while [ $(get_percentage) -ne 100 ] ;
do
sleep 0.25
done
# Add delay or a warning message here if necessary
shutdown_system