Created
June 21, 2018 07:23
-
-
Save silky/6a3166dc189c3f93b5b3b2167c57db63 to your computer and use it in GitHub Desktop.
Script to bump sound using `amixer` from `alsa-utils`
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 stack | |
-- stack script --resolver lts-8.12 | |
-- --package turtle | |
-- --package string-conv | |
-- Compile like: | |
-- > stack exec --package turtle --package string-conv -- ghc --make BumpSound.hs | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
import qualified Control.Foldl as Fold | |
import Data.String.Conv | |
import Control.Monad | |
stepSize = 4 | |
maxSound = 70 | |
minSound = 0 | |
shell' c = shell c empty | |
parser :: Parser (Text) | |
parser = argText "direction" "Either 'up' or 'down'." | |
main :: IO () | |
main = void $ do | |
cmd <- options "amixer sound bumper" parser | |
vol <- currentVolume | |
case cmd of | |
"down" -> step vol (-stepSize) | |
"up" -> step vol stepSize | |
step :: Maybe Int -> Int -> IO () | |
step Nothing _ = return () | |
step (Just v) s = do | |
sh $ shell' ("amixer set Master " <> (toS (show nextVol)) <> "%") | |
where | |
nextVol :: Int | |
nextVol = min (max minSound (v+s)) maxSound | |
currentVolume :: IO (Maybe Int) | |
currentVolume = do | |
v <- flip fold Fold.head $ inshell "amixer get Master | grep '\\[on\\]' | awk '{ print $4 }' | grep -Po '\\d+'" "" | |
return $ read . toS . lineToText <$> v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment