Monthly Archives: May 2016

Be notified when critical battery level is reached

Ever happened to be focused on something and miss the fact that your laptop is running out of battery? And to lose your work?
Yesterday happened twice! "Really? Hmm... I need to fix this as soon as possible."
I googled a bit and this stackexchange post  popped up. Nice, great! But being notified even when you're charging your laptop it's not nice and I had to change the solution a bit:

[codesyntax lang="bash"]

cat .notify-send_setup

[/codesyntax]

#!/bin/bash
touch $HOME/.dbus/Xdbus
chmod 600 $HOME/.dbus/Xdbus
env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.dbus/Xdbus
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.dbus/Xdbus

exit 0

[codesyntax lang="bash"]

cat .battnotif

[/codesyntax]

#!/bin/bash
export DISPLAY=:0
XAUTHORITY=$HOME/.Xauthority

if [ -r "$HOME/.dbus/Xdbus" ]; then
    . "$HOME/.dbus/Xdbus"
fi

battery_level=$(acpi -b | grep -P -o '[0-9]+(?=%)')
STATUS=$(acpi -b | awk '{print $3'} | sed -e 's/,//g')

if [ $battery_level -le 15 ] && [ $STATUS == "Discharging" ]
then
    /usr/bin/notify-send -u critical "Battery low" "Battery level is ${battery_level}%!"
    echo 'batt low' >> $HOME/cron.log
fi

echo 'ran batt' >> $HOME/cron.log

How to set up multiple monitors in linux (using xrandr)

If you would need to set up your displays once every week or less using the GUI is just fine. I had to do it every morning and after a while it became really annoying.

Turn off the HDMI display:
[codesyntax lang="bash"]

xrandr --output HDMI1 --off

[/codesyntax]

Turn on the HDMI display and set it as primary display:
[codesyntax lang="bash"]

xrandr --output HDMI1 --mode 1920x1080 --primary --left-of eDP1

[/codesyntax]