diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-07-18 15:45:02 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-07-18 15:45:02 +0200 |
commit | 054955db38bb571c294b5d86c78639e3b1091031 (patch) | |
tree | 6dd4b42405c4693cd35ad6b7d07b163cfcb584f5 /.local/bin/mixer-set | |
parent | Added emacs config (diff) | |
download | dotfiles-bsd-054955db38bb571c294b5d86c78639e3b1091031.tar.gz dotfiles-bsd-054955db38bb571c294b5d86c78639e3b1091031.tar.bz2 dotfiles-bsd-054955db38bb571c294b5d86c78639e3b1091031.tar.xz dotfiles-bsd-054955db38bb571c294b5d86c78639e3b1091031.tar.zst dotfiles-bsd-054955db38bb571c294b5d86c78639e3b1091031.zip |
Added scripts
Diffstat (limited to '.local/bin/mixer-set')
-rwxr-xr-x | .local/bin/mixer-set | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/.local/bin/mixer-set b/.local/bin/mixer-set new file mode 100755 index 0000000..e74beeb --- /dev/null +++ b/.local/bin/mixer-set @@ -0,0 +1,83 @@ +#!/usr/local/bin/perl -w + +use strict; +use warnings; +use Term::ANSIColor; + +sub main { + my $argc = $#ARGV + 1; + if ($argc == 0) { + print "Argument needed - [" + . colored("lower", 'bold') + . " - " + . colored("raise", 'bold') + . " - " + . colored("toggle", 'bold') + . "]\n"; + exit 1; + } + elsif ($argc > 1) { + print "Too many arguments, only one needed\n"; + exit 2; + } + my $curr_vol = 0; + my $curr_vol_cmd = "/usr/sbin/mixer vol | /usr/bin/awk -F ':' '{print \$2}'"; + if ($ARGV[0] eq "lower") { + system('/usr/local/bin/dash', + '-c', + '/usr/sbin/mixer vol -5 >/dev/null 2>&1'); + $curr_vol = `$curr_vol_cmd`; + chomp $curr_vol; + system('/usr/local/bin/dash', + '-c', + '/usr/local/bin/notify-send -u low -t 400 "Volume lowered - ' . $curr_vol . '%"'); + exit; + } + elsif ($ARGV[0] eq "raise") { + system('/usr/local/bin/dash', + '-c', + '/usr/sbin/mixer vol +5 >/dev/null 2>&1'); + $curr_vol = `$curr_vol_cmd`; + chomp $curr_vol; + system('/usr/local/bin/dash', + '-c', + '/usr/local/bin/notify-send -u low -t 400 "Volume raised - ' . $curr_vol . '%"'); + exit; + } + elsif ($ARGV[0] eq "toggle") { + my $tmp_file = '/tmp/mixervol'; + $curr_vol = `$curr_vol_cmd`; + chomp $curr_vol; + if ($curr_vol > 0) { + open(my $fh, '>:encoding(UTF-8)', $tmp_file); + print $fh $curr_vol; + close($fh); + system('/usr/local/bin/dash', + '-c', + '/usr/sbin/mixer vol 0 >/dev/null 2>&1'); + system('/usr/local/bin/dash', + '-c', + '/usr/local/bin/notify-send -u low -t 1750 "Volume muted"'); + } + else { + open(my $fh, '<:encoding(UTF-8)', $tmp_file); + $curr_vol = <$fh>; + close($fh); + system('/usr/local/bin/dash', + '-c', + '/usr/sbin/mixer vol ' . $curr_vol . ' >/dev/null 2>&1'); + system('/usr/local/bin/dash', + '-c', + '/usr/local/bin/notify-send -u low -t 1750 "Volume restored - ' . $curr_vol . '%"'); + } + exit; + } + else { + print "Unrecognized argument: " . $ARGV[0] . "\n"; + } + exit; +} + +main(); + +__END__ |