Simple workaround to keep PC alive playing songs in Amarok and Gnome

During last months, I must confess, I got a new music player: Amarok.

Now, I would not fall in flame, but Rhythmbox seems still incomplete (and a bit bugged) if compared to Amarok. And, sadly, this is a fact, not an opinion (lol, and this is flame).

Anyway.. Amarok is not able to keep your PC alive when plays something, so if you set a hibernate time in gnome-settings you will see your PC going to sleep while you’re listening some song. And this is really bad..

This little script checks if Amarok is running (and it’s playing something as well) and set hibernate time to 0 (that means: no hibernate) in gnome-settings.

#!/bin/bash

# you MUST set this accoring with your QT installation
QDBUS=/usr/lib/x86_64-linux-gnu/qt4/bin/qdbus

# change these as you wish
# daemon time in seconds
TIME_DAEMON=10
# time to hibernate in seconds
TIME_HIBERNATE=600

# do not touch these
KEY=/org/gnome/settings-daemon/plugins/power/sleep-inactive-ac-timeout
QDBUS_CMD="org.mpris.MediaPlayer2.amarok /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus"

function amarok_on() {
  dconf write $KEY 0
}

function amarok_off() {
  dconf write $KEY $TIME_HIBERNATE
}

function check() {
  STATUS=`$QDBUS $QDBUS_CMD`
  if [ "$STATUS" == "Playing" ] ; then
    amarok_on
  else
    amarok_off
  fi
}

while `sleep $TIME_DAEMON` ; do check ; done

Obviously, you have to run this script when a gnome session starts (Startup applications).

5 thoughts on “Simple workaround to keep PC alive playing songs in Amarok and Gnome

  1. Jeff

    Y’know, it would make more sense for you to file a bug report and provide a patch for Amarok to inhibit power saving properly instead of spending time coming up with a hack to work around the issue and writing a blog post about it :)

    Reply
  2. Pingback: Links 31/5/2013: Vivaldi Tablet is Coming, GNU/Linux Growing In China | Techrights

  3. Christin

    Thank you for the good writeup. It in truth was once a entertainment
    account it. Glance complicated to far brought agreeable
    from you! By the way, how could we keep up a correspondence?

    Reply

Leave a Reply