#!/usr/bin/ruby # by Brian Carper # http://briancarper.net # # This script gets the currently playing artist # and title from Amarok via DCOP. # # We trap STDERR because Amarok dumps an error to # STDERR if nothing is playing, and I don't want # conky to spew error text into my console (or # anywhere else). # Wrap to 35 characters at most, but break only # at word boundaries. def wrap(text) text.gsub(/[^\n]{1,35}(?=\s|$)/, "\\0\n") end stderr_bak = STDERR STDERR.reopen('/dev/null', 'w') output = `dcop amarok player nowPlaying` if output.match(/\S/) then puts wrap(output) else puts 'Nothing.' end STDERR = stderr_backup