#!/usr/bin/env perl use strict; use warnings; use Capture::Tiny qw(capture); use Sys::Hostname qw(hostname); use constant { MIXER_PATH => '/usr/sbin/mixer', NOTIF_PATH => '/usr/local/bin/herbe' }; sub notify { my ($str) = @_; my $pid = fork(); if (not $pid) { exec(NOTIF_PATH, $str); } return; }; sub mic { my $rec_vol; my $host; $host = hostname(); if ($host eq "po-rbo.ln.ysosecure.com") { system('/usr/bin/pactl', 'set-source-mute', '@DEFAULT_SOURCE@', 'toggle'); my $muted = `/usr/bin/pactl get-source-mute \@DEFAULT_SOURCE\@ | awk '{print \$2}'`; chomp $muted; if ($muted eq "yes") { notify(' muted'); } else { notify(' restored'); } exit; } $rec_vol = `mixer rec | awk -F ':' '{print \$2}'`; chomp $rec_vol; if ($rec_vol == 0) { capture { system(MIXER_PATH, 'rec', '100'); }; notify(' microphone restored'); } else { capture { system(MIXER_PATH, 'rec', '0'); notify(' microphone muted'); }; } system('kill -68 $(pidof dwmblocks)'); return; } mic(); __END__