How to get volume level from the command line?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
11
down vote

favorite
2












I have a text status bar on a tiling window manager and I am using tcl to feed information to it. At the moment I need a command line that output the volume level 0% to 100%. I am using Arch Linux.










share|improve this question























  • Looks like you should be able to do it by parsing /var/lib/alsa/asound.state.
    – jordanm
    Sep 5 '13 at 19:22










  • I just found amixer. Thanks
    – milarepa
    Sep 5 '13 at 19:51










  • Note: in the future, saying you're using Arch isn't really relevant. What actually matters is what sound subsystem you're using, e.g. ALSA, OSS or PulseAudio.
    – strugee
    Sep 5 '13 at 19:55







  • 1




    Instead of adding "closed" to your title, you should just answer your own question and leave it
    – jordanm
    Sep 5 '13 at 19:55














up vote
11
down vote

favorite
2












I have a text status bar on a tiling window manager and I am using tcl to feed information to it. At the moment I need a command line that output the volume level 0% to 100%. I am using Arch Linux.










share|improve this question























  • Looks like you should be able to do it by parsing /var/lib/alsa/asound.state.
    – jordanm
    Sep 5 '13 at 19:22










  • I just found amixer. Thanks
    – milarepa
    Sep 5 '13 at 19:51










  • Note: in the future, saying you're using Arch isn't really relevant. What actually matters is what sound subsystem you're using, e.g. ALSA, OSS or PulseAudio.
    – strugee
    Sep 5 '13 at 19:55







  • 1




    Instead of adding "closed" to your title, you should just answer your own question and leave it
    – jordanm
    Sep 5 '13 at 19:55












up vote
11
down vote

favorite
2









up vote
11
down vote

favorite
2






2





I have a text status bar on a tiling window manager and I am using tcl to feed information to it. At the moment I need a command line that output the volume level 0% to 100%. I am using Arch Linux.










share|improve this question















I have a text status bar on a tiling window manager and I am using tcl to feed information to it. At the moment I need a command line that output the volume level 0% to 100%. I am using Arch Linux.







command-line arch-linux scripting volume






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 5 '13 at 22:39









Gilles

520k12510381569




520k12510381569










asked Sep 5 '13 at 18:57









milarepa

5612718




5612718











  • Looks like you should be able to do it by parsing /var/lib/alsa/asound.state.
    – jordanm
    Sep 5 '13 at 19:22










  • I just found amixer. Thanks
    – milarepa
    Sep 5 '13 at 19:51










  • Note: in the future, saying you're using Arch isn't really relevant. What actually matters is what sound subsystem you're using, e.g. ALSA, OSS or PulseAudio.
    – strugee
    Sep 5 '13 at 19:55







  • 1




    Instead of adding "closed" to your title, you should just answer your own question and leave it
    – jordanm
    Sep 5 '13 at 19:55
















  • Looks like you should be able to do it by parsing /var/lib/alsa/asound.state.
    – jordanm
    Sep 5 '13 at 19:22










  • I just found amixer. Thanks
    – milarepa
    Sep 5 '13 at 19:51










  • Note: in the future, saying you're using Arch isn't really relevant. What actually matters is what sound subsystem you're using, e.g. ALSA, OSS or PulseAudio.
    – strugee
    Sep 5 '13 at 19:55







  • 1




    Instead of adding "closed" to your title, you should just answer your own question and leave it
    – jordanm
    Sep 5 '13 at 19:55















Looks like you should be able to do it by parsing /var/lib/alsa/asound.state.
– jordanm
Sep 5 '13 at 19:22




Looks like you should be able to do it by parsing /var/lib/alsa/asound.state.
– jordanm
Sep 5 '13 at 19:22












I just found amixer. Thanks
– milarepa
Sep 5 '13 at 19:51




I just found amixer. Thanks
– milarepa
Sep 5 '13 at 19:51












Note: in the future, saying you're using Arch isn't really relevant. What actually matters is what sound subsystem you're using, e.g. ALSA, OSS or PulseAudio.
– strugee
Sep 5 '13 at 19:55





Note: in the future, saying you're using Arch isn't really relevant. What actually matters is what sound subsystem you're using, e.g. ALSA, OSS or PulseAudio.
– strugee
Sep 5 '13 at 19:55





1




1




Instead of adding "closed" to your title, you should just answer your own question and leave it
– jordanm
Sep 5 '13 at 19:55




Instead of adding "closed" to your title, you should just answer your own question and leave it
– jordanm
Sep 5 '13 at 19:55










3 Answers
3






active

oldest

votes

















up vote
11
down vote



accepted










A one-liner to parse amixer's output for volume in a status bar:



awk -F"" '/dB/ print $2 ' <(amixer sget Master)





share|improve this answer




















  • what does mean?
    – approximatenumber
    May 24 '16 at 14:44






  • 3




    @approximatenumber It sets the field separator as either ] or [.
    – jasonwryan
    May 24 '16 at 18:38










  • Cool. I didn't know you could have a regex for the F
    – mihai
    Mar 15 '17 at 17:33










  • How would you store this command in a variable ?
    – mike23
    Jan 16 at 21:18










  • @mike23 vol=$(awk '/%/ gsub(/[[]]/,""); print $4' <(amixer sget Master))
    – jasonwryan
    Jan 16 at 21:20

















up vote
8
down vote













You can use amixer to do this.



Examples



$ amixer get Master
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [off]
Front Right: Playback 65536 [100%] [off]


You can also change it and mute it like so:



set volume 75%



$ amixer set Master 75%
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 49152 [75%] [on]
Front Right: Playback 49152 [75%] [on]


mute/unmute



$ amixer set Master toggle
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined penum
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [on]
Front Right: Playback 65536 [100%] [on]


You can quiet the output if you don't want to see any of it with the --quiet switch.



$ amixer --quiet set Master 75%
$





share|improve this answer



























    up vote
    2
    down vote













    Right



    amixer sget Master | grep 'Right:' | awk -F'' ' print $2 '
    85%


    Left



    amixer sget Master | grep 'Left:' | awk -F'' ' print $2 '
    85%


    Sound server



    If you are not using pulseaudio as default you can specify to amixer what server to use with -D pulse



    amixer -D pulse sget Master | grep 'Left:' | awk -F'' ' print $2 '
    85%





    share|improve this answer






















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f89571%2fhow-to-get-volume-level-from-the-command-line%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      11
      down vote



      accepted










      A one-liner to parse amixer's output for volume in a status bar:



      awk -F"" '/dB/ print $2 ' <(amixer sget Master)





      share|improve this answer




















      • what does mean?
        – approximatenumber
        May 24 '16 at 14:44






      • 3




        @approximatenumber It sets the field separator as either ] or [.
        – jasonwryan
        May 24 '16 at 18:38










      • Cool. I didn't know you could have a regex for the F
        – mihai
        Mar 15 '17 at 17:33










      • How would you store this command in a variable ?
        – mike23
        Jan 16 at 21:18










      • @mike23 vol=$(awk '/%/ gsub(/[[]]/,""); print $4' <(amixer sget Master))
        – jasonwryan
        Jan 16 at 21:20














      up vote
      11
      down vote



      accepted










      A one-liner to parse amixer's output for volume in a status bar:



      awk -F"" '/dB/ print $2 ' <(amixer sget Master)





      share|improve this answer




















      • what does mean?
        – approximatenumber
        May 24 '16 at 14:44






      • 3




        @approximatenumber It sets the field separator as either ] or [.
        – jasonwryan
        May 24 '16 at 18:38










      • Cool. I didn't know you could have a regex for the F
        – mihai
        Mar 15 '17 at 17:33










      • How would you store this command in a variable ?
        – mike23
        Jan 16 at 21:18










      • @mike23 vol=$(awk '/%/ gsub(/[[]]/,""); print $4' <(amixer sget Master))
        – jasonwryan
        Jan 16 at 21:20












      up vote
      11
      down vote



      accepted







      up vote
      11
      down vote



      accepted






      A one-liner to parse amixer's output for volume in a status bar:



      awk -F"" '/dB/ print $2 ' <(amixer sget Master)





      share|improve this answer












      A one-liner to parse amixer's output for volume in a status bar:



      awk -F"" '/dB/ print $2 ' <(amixer sget Master)






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Sep 5 '13 at 20:58









      jasonwryan

      48.5k14133182




      48.5k14133182











      • what does mean?
        – approximatenumber
        May 24 '16 at 14:44






      • 3




        @approximatenumber It sets the field separator as either ] or [.
        – jasonwryan
        May 24 '16 at 18:38










      • Cool. I didn't know you could have a regex for the F
        – mihai
        Mar 15 '17 at 17:33










      • How would you store this command in a variable ?
        – mike23
        Jan 16 at 21:18










      • @mike23 vol=$(awk '/%/ gsub(/[[]]/,""); print $4' <(amixer sget Master))
        – jasonwryan
        Jan 16 at 21:20
















      • what does mean?
        – approximatenumber
        May 24 '16 at 14:44






      • 3




        @approximatenumber It sets the field separator as either ] or [.
        – jasonwryan
        May 24 '16 at 18:38










      • Cool. I didn't know you could have a regex for the F
        – mihai
        Mar 15 '17 at 17:33










      • How would you store this command in a variable ?
        – mike23
        Jan 16 at 21:18










      • @mike23 vol=$(awk '/%/ gsub(/[[]]/,""); print $4' <(amixer sget Master))
        – jasonwryan
        Jan 16 at 21:20















      what does mean?
      – approximatenumber
      May 24 '16 at 14:44




      what does mean?
      – approximatenumber
      May 24 '16 at 14:44




      3




      3




      @approximatenumber It sets the field separator as either ] or [.
      – jasonwryan
      May 24 '16 at 18:38




      @approximatenumber It sets the field separator as either ] or [.
      – jasonwryan
      May 24 '16 at 18:38












      Cool. I didn't know you could have a regex for the F
      – mihai
      Mar 15 '17 at 17:33




      Cool. I didn't know you could have a regex for the F
      – mihai
      Mar 15 '17 at 17:33












      How would you store this command in a variable ?
      – mike23
      Jan 16 at 21:18




      How would you store this command in a variable ?
      – mike23
      Jan 16 at 21:18












      @mike23 vol=$(awk '/%/ gsub(/[[]]/,""); print $4' <(amixer sget Master))
      – jasonwryan
      Jan 16 at 21:20




      @mike23 vol=$(awk '/%/ gsub(/[[]]/,""); print $4' <(amixer sget Master))
      – jasonwryan
      Jan 16 at 21:20












      up vote
      8
      down vote













      You can use amixer to do this.



      Examples



      $ amixer get Master
      Simple mixer control 'Master',0
      Capabilities: pvolume pswitch pswitch-joined penum
      Playback channels: Front Left - Front Right
      Limits: Playback 0 - 65536
      Mono:
      Front Left: Playback 65536 [100%] [off]
      Front Right: Playback 65536 [100%] [off]


      You can also change it and mute it like so:



      set volume 75%



      $ amixer set Master 75%
      Simple mixer control 'Master',0
      Capabilities: pvolume pswitch pswitch-joined penum
      Playback channels: Front Left - Front Right
      Limits: Playback 0 - 65536
      Mono:
      Front Left: Playback 49152 [75%] [on]
      Front Right: Playback 49152 [75%] [on]


      mute/unmute



      $ amixer set Master toggle
      Simple mixer control 'Master',0
      Capabilities: pvolume pswitch pswitch-joined penum
      Playback channels: Front Left - Front Right
      Limits: Playback 0 - 65536
      Mono:
      Front Left: Playback 65536 [100%] [on]
      Front Right: Playback 65536 [100%] [on]


      You can quiet the output if you don't want to see any of it with the --quiet switch.



      $ amixer --quiet set Master 75%
      $





      share|improve this answer
























        up vote
        8
        down vote













        You can use amixer to do this.



        Examples



        $ amixer get Master
        Simple mixer control 'Master',0
        Capabilities: pvolume pswitch pswitch-joined penum
        Playback channels: Front Left - Front Right
        Limits: Playback 0 - 65536
        Mono:
        Front Left: Playback 65536 [100%] [off]
        Front Right: Playback 65536 [100%] [off]


        You can also change it and mute it like so:



        set volume 75%



        $ amixer set Master 75%
        Simple mixer control 'Master',0
        Capabilities: pvolume pswitch pswitch-joined penum
        Playback channels: Front Left - Front Right
        Limits: Playback 0 - 65536
        Mono:
        Front Left: Playback 49152 [75%] [on]
        Front Right: Playback 49152 [75%] [on]


        mute/unmute



        $ amixer set Master toggle
        Simple mixer control 'Master',0
        Capabilities: pvolume pswitch pswitch-joined penum
        Playback channels: Front Left - Front Right
        Limits: Playback 0 - 65536
        Mono:
        Front Left: Playback 65536 [100%] [on]
        Front Right: Playback 65536 [100%] [on]


        You can quiet the output if you don't want to see any of it with the --quiet switch.



        $ amixer --quiet set Master 75%
        $





        share|improve this answer






















          up vote
          8
          down vote










          up vote
          8
          down vote









          You can use amixer to do this.



          Examples



          $ amixer get Master
          Simple mixer control 'Master',0
          Capabilities: pvolume pswitch pswitch-joined penum
          Playback channels: Front Left - Front Right
          Limits: Playback 0 - 65536
          Mono:
          Front Left: Playback 65536 [100%] [off]
          Front Right: Playback 65536 [100%] [off]


          You can also change it and mute it like so:



          set volume 75%



          $ amixer set Master 75%
          Simple mixer control 'Master',0
          Capabilities: pvolume pswitch pswitch-joined penum
          Playback channels: Front Left - Front Right
          Limits: Playback 0 - 65536
          Mono:
          Front Left: Playback 49152 [75%] [on]
          Front Right: Playback 49152 [75%] [on]


          mute/unmute



          $ amixer set Master toggle
          Simple mixer control 'Master',0
          Capabilities: pvolume pswitch pswitch-joined penum
          Playback channels: Front Left - Front Right
          Limits: Playback 0 - 65536
          Mono:
          Front Left: Playback 65536 [100%] [on]
          Front Right: Playback 65536 [100%] [on]


          You can quiet the output if you don't want to see any of it with the --quiet switch.



          $ amixer --quiet set Master 75%
          $





          share|improve this answer












          You can use amixer to do this.



          Examples



          $ amixer get Master
          Simple mixer control 'Master',0
          Capabilities: pvolume pswitch pswitch-joined penum
          Playback channels: Front Left - Front Right
          Limits: Playback 0 - 65536
          Mono:
          Front Left: Playback 65536 [100%] [off]
          Front Right: Playback 65536 [100%] [off]


          You can also change it and mute it like so:



          set volume 75%



          $ amixer set Master 75%
          Simple mixer control 'Master',0
          Capabilities: pvolume pswitch pswitch-joined penum
          Playback channels: Front Left - Front Right
          Limits: Playback 0 - 65536
          Mono:
          Front Left: Playback 49152 [75%] [on]
          Front Right: Playback 49152 [75%] [on]


          mute/unmute



          $ amixer set Master toggle
          Simple mixer control 'Master',0
          Capabilities: pvolume pswitch pswitch-joined penum
          Playback channels: Front Left - Front Right
          Limits: Playback 0 - 65536
          Mono:
          Front Left: Playback 65536 [100%] [on]
          Front Right: Playback 65536 [100%] [on]


          You can quiet the output if you don't want to see any of it with the --quiet switch.



          $ amixer --quiet set Master 75%
          $






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 5 '13 at 20:43









          slm

          243k66502669




          243k66502669




















              up vote
              2
              down vote













              Right



              amixer sget Master | grep 'Right:' | awk -F'' ' print $2 '
              85%


              Left



              amixer sget Master | grep 'Left:' | awk -F'' ' print $2 '
              85%


              Sound server



              If you are not using pulseaudio as default you can specify to amixer what server to use with -D pulse



              amixer -D pulse sget Master | grep 'Left:' | awk -F'' ' print $2 '
              85%





              share|improve this answer


























                up vote
                2
                down vote













                Right



                amixer sget Master | grep 'Right:' | awk -F'' ' print $2 '
                85%


                Left



                amixer sget Master | grep 'Left:' | awk -F'' ' print $2 '
                85%


                Sound server



                If you are not using pulseaudio as default you can specify to amixer what server to use with -D pulse



                amixer -D pulse sget Master | grep 'Left:' | awk -F'' ' print $2 '
                85%





                share|improve this answer
























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Right



                  amixer sget Master | grep 'Right:' | awk -F'' ' print $2 '
                  85%


                  Left



                  amixer sget Master | grep 'Left:' | awk -F'' ' print $2 '
                  85%


                  Sound server



                  If you are not using pulseaudio as default you can specify to amixer what server to use with -D pulse



                  amixer -D pulse sget Master | grep 'Left:' | awk -F'' ' print $2 '
                  85%





                  share|improve this answer














                  Right



                  amixer sget Master | grep 'Right:' | awk -F'' ' print $2 '
                  85%


                  Left



                  amixer sget Master | grep 'Left:' | awk -F'' ' print $2 '
                  85%


                  Sound server



                  If you are not using pulseaudio as default you can specify to amixer what server to use with -D pulse



                  amixer -D pulse sget Master | grep 'Left:' | awk -F'' ' print $2 '
                  85%






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered Apr 7 at 13:56









                  intika

                  1695




                  1695



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f89571%2fhow-to-get-volume-level-from-the-command-line%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown






                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?