Skip to content

Instantly share code, notes, and snippets.

@fser
Created November 7, 2012 15:01
Show Gist options
  • Save fser/4032095 to your computer and use it in GitHub Desktop.
Save fser/4032095 to your computer and use it in GitHub Desktop.
update awesome widget with mpc current song
#!/usr/bin/env perl
# François Serman <aifsair@gmail.com>
# 07 nov 2012
# Initial version: updates awesome widget perdiodicaly, or when killed
# via SIGUSR1
#
# Awesome setup:
# mpdbox = widget({ type = "textbox", name = "mpdbox" })
# ...
# mywibox[s].widgets = {
# {
# ... ,
# mpdbox,
# ...
sub current_song
{
open (my $mpc, "mpc current 2>&1 |") or die "mpc: $!";
my $music = <$mpc>;
close ($mpc);
$music =~ s@\n@@;
return 0 if ($music =~ /error/) ;
$music;
}
sub update_display
{
my $song = current_song;
my $full_cmd = sprintf(qq/mpdbox.text = "[ %s ]"/, ($song ? $song : "MPD"));
open(my $process, "| awesome-client") or die "awesome-client: $!";
print $process $full_cmd;
close ($process);
}
$SIG{"USR1"} = \&update_display;
while (1) {
update_display;
sleep 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment