-
Notifications
You must be signed in to change notification settings - Fork 505
naughty_status.rb
Blake Grotewold edited this page Mar 10, 2014
·
1 revision
This is for awesome WM users only. It requires ruby to run.
This script displays status differently depending on hostname, so that the same configuration shows large cover art on the second screen for my desktop and a smaller display on the main screen for my laptop. Naughty has plenty of other options, see here.
#!/usr/bin/env ruby
# encoding: UTF-8
# Hash contains:
#{
# "status"=>"playing",
# "file"=>"/my/music/path.mp3",
# "artist"=>"Some Artist",
# "album"=>"Some Album",
# "tracknumber"=>"0",
# "title"=>"Some song",
# "date"=>"2000",
# "duration"=>"288"
#}
i = Hash[ARGV.each_slice(2).to_a]
# process variables that need it
artist = i['artist']
album = i['album']
date = i['date']
tracknumber = i['tracknumber'].to_i
title = i['title']
status = i['status'].capitalize
# build the text string
text = artist || "Unknown Artist"
text += " / #{album}" if album
text += " (#{date})" if date
text += "\\n"
text += "#{"%02d" % tracknumber} - " if tracknumber
text += title || "Untitled track"
# put on second screen on desktop, also make art bigger
if %x{hostname}.chomp == 'box'
screen = 2
icon_size = 400
else
screen = 1
icon_size = 200
end
# build the command
naughty_command = %Q<naughty.notify({title="#{status}", text="#{text}", timeout=8, screen=#{screen},>
if i['artist'] && i['album']
naughty_command += %Q< icon="/path/to/art/#{artist}--#{album}.jpg", icon_size=#{icon_size}>
end
naughty_command += %Q<})>
# pipe the Naughty command to awesome-client
IO::popen('awesome-client -', 'w'){|io| io << naughty_command}