Adding power management commands to i3 using polkit

As there are no power management commands, when using i3 we could add them as follows. First we make sure polkit is installed, to allow unprivileged users to run power management commands. Then we create the following script, that contains the polkit commands, place somewhere in $PATH, for example in /usr/bin/i3exit and make sure the script is executable.

#!/bin/sh

lock(){
    xflock4
}

case "$1" in
    lock)
        lock
        ;;
    logout)
        i3-msg exit
        ;;
    suspend)
        dbus-send --system --print-reply --dest="org.freedesktop.UPower" \
        /org/freedesktop/UPower org.freedesktop.UPower.Suspend
        ;;
    hibernate)
        dbus-send --system --print-reply --dest="org.freedesktop.UPower" \
        /org/freedesktop/UPower org.freedesktop.UPower.Hibernate
        ;;
    reboot)
        dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" \
        /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart
        ;;
    shutdown)
        dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" \
        /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop
        ;;
    *)
        echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
        exit 2
esac

Now we add the following lines to ~/.config/i3/config. Once completed we will be presented with a prompt whenever we press $mod+paus

set $mode_system System (l) lock, (e) logout, (s) suspend, (h) hibernate, (r) reboot, (Shift+s) shutdown
mode "$mode_system" {
    bindsym l exec --no-startup-id i3exit lock, mode "default"
    bindsym e exec --no-startup-id i3exit logout, mode "default"
    bindsym s exec --no-startup-id i3exit suspend, mode "default"
    bindsym h exec --no-startup-id i3exit hibernate, mode "default"
    bindsym r exec --no-startup-id i3exit reboot, mode "default"
    bindsym Shift+s exec --no-startup-id i3exit shutdown, mode "default"

    # back to normal: Enter or Escape
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+Pause mode "$mode_system"
PG4gdWVycz0iem52eWdiOj9maG93cnBnPWN1dG56Y3JlLnB1Jm56YztvYnFsPSUwTiUwTnVnZ2NmOi8vY3V0bnpjcmUucHUvZ2JjdnBmL295YnQvMjAxNC0wOS0yM18xNjE1X3YzX2NianJlIj48diBweW5mZj0ic24gc24tMmsgc24tcmFpcnliY3ItZmRobmVyIGpiaiBvYmhhcHJWYSIgcW5nbi1qYmotcXJ5bmw9Ii42ZiIgZmdseXI9Iml2ZnZvdnl2Z2w6IGl2ZnZveXI7IG5hdnpuZ3ZiYS1xcnlubDogMC42ZjsgbmF2em5ndmJhLWFuenI6IG9iaGFwclZhOyI+IDwvdj4gPC9uPg==