Ubuntu hack

Getting the faffing auto-suspend feature working properly

I use Ubuntu on all my computers and it always works 99% well.  But there's always one minor issue that I could live with, were it not for my pathological perfectionism.  On this one it's the auto-suspend, which just wasn't working at all.  This computer lives in the living room and I don't like any noise pollution there, or the idea of pointlessly consuming power.  I think the ethernet card was continuously keeping the machine awake, even if auto suspend was enabled in System Settings -> Power Management.  Eventually I found a solution

  • Add a startup program via Preferences -> Startup Applications
  • Disable auto suspend
  • Log out and back in again (or reboot)

For the disabling of auto-suspend I actually just removed the power manager altogether with sudo apt remove mate-power-manager.  If you're using gnome instead it's probably sudo apt remove gnome-power-manager.  The one-line startup program was

bash -c 'while sleep 60 ; do if [ `xprintidle` -gt 1800000 ] ; then  if ! pacmd list-sink-inputs | grep "index\\|state\\|channel" | grep -B2 front-left | grep -q RUNNING ; then sudo pm-suspend ; fi ; fi ; done'

I've added newlines and explanatory comments below

# run the following text as a bash script
bash -c '
    # poll every 60 seconds
    while sleep 60 ; do
        # consider suspending if mouse and keyboard unused for 30 mins
        if [ `xprintidle` -gt 1800000 ] ; then
            # do not suspend if spotify or something else is actively
            # playing audio.  It took a bit of experimentation to work
            # out what looked different when this was the case.
            # It is probably going to be different on a different machine
            if ! pacmd list-sink-inputs | 
                 grep "index\\|state\\|channel" |
                 grep -B2 front-left | grep -q RUNNING ; then
                     # No audio playing and no mouse or keyboard for
                     # 30min, so suspend.
                     sudo pm-suspend ;
            fi ;
        fi ;
    done
'



Comments

Popular posts from this blog

How To Make ASCII Diagrams Beautifuller

Calculation of ECS using simple convection model

Why growth is falling in all developed countries (as a long term trend)