Created
November 7, 2012 15:01
-
-
Save fser/4032095 to your computer and use it in GitHub Desktop.
update awesome widget with mpc current song
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# François Serman <[email protected]> | |
# 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