[SOLVED] amixer output problem

If none of the more specific forums is the right place to ask

[SOLVED] amixer output problem

Postby pawRoot » 2018-03-12 03:59

Hi

I am trying to get volume levels from amixer so i can use it in Conky, if i type this
Code: Select all
amixer -c 0 get Master | grep Mono:


i am getting
Code: Select all
amixer: Unable to find simple control 'Master',0


why is that ? if i just type amixer get Master
Code: Select all
amixer get Master
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 36043 [55%] [on]
  Front Right: Playback 36043 [55%] [on]


Any ideas? :)
Last edited by pawRoot on 2018-03-12 18:55, edited 1 time in total.
User avatar
pawRoot
 
Posts: 515
Joined: 2016-12-28 18:26
Location: Poland

Re: amixer output problem

Postby Dai_trying » 2018-03-12 08:31

This works for me
Code: Select all
amixer -c 0 get Master | grep Mono: | awk '{ print $4 }'

which gives the output
Code: Select all
[92%]
Dai_trying
 
Posts: 531
Joined: 2016-01-07 12:25

Re: amixer output problem

Postby None1975 » 2018-03-12 14:45

Hello. In my Xmobar, i use this small script. Works like a charm
Code: Select all
#!/bin/bash

vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else {
print $2 }}' | head -n 1)

echo Vol: $vol

exit 0


Image
OS: Debian 9.4 / WM: Xmonad
Debian Wiki | DontBreakDebian, My config files in github
Linux User #607425
User avatar
None1975
 
Posts: 625
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: amixer output problem

Postby pawRoot » 2018-03-12 16:29

Dai_trying wrote:This works for me
Code: Select all
amixer -c 0 get Master | grep Mono: | awk '{ print $4 }'

which gives the output
Code: Select all
[92%]


Code: Select all
amixer: Unable to find simple control 'Master',0


None1975 wrote:Hello. In my Xmobar, i use this small script. Works like a charm
Code: Select all
#!/bin/bash

vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else {
print $2 }}' | head -n 1)

echo Vol: $vol

exit 0


Image


I am trying to get volume by only using Conky, no external scripts.
I already did it once and it worked fine, but i lost the config :(
User avatar
pawRoot
 
Posts: 515
Joined: 2016-12-28 18:26
Location: Poland

Re: amixer output problem

Postby Dai_trying » 2018-03-12 16:34

and this doesn't work??

Code: Select all
${exec amixer -c 0 get Master | grep Mono: | awk '{ print $4 }'}
Dai_trying
 
Posts: 531
Joined: 2016-01-07 12:25

Re: amixer output problem

Postby pawRoot » 2018-03-12 16:35

^nope it doesn't display anything :x
User avatar
pawRoot
 
Posts: 515
Joined: 2016-12-28 18:26
Location: Poland

Re: amixer output problem

Postby Dai_trying » 2018-03-12 16:39

I just noticed you need to select the left or right audio and read them separately and probably display each of them in your conky, just change the grep to search for Left: or Right: and change the awk to spit out the 5th word.
Dai_trying
 
Posts: 531
Joined: 2016-01-07 12:25

Re: amixer output problem

Postby pawRoot » 2018-03-12 16:41

Code: Select all
amixer -c 0 get Master | grep Left: | awk '{ print $5 }'


Something like that?

it still gives me same error
User avatar
pawRoot
 
Posts: 515
Joined: 2016-12-28 18:26
Location: Poland

Re: amixer output problem

Postby Dai_trying » 2018-03-12 17:50

how about you try this one...

Code: Select all
amixer get Master | grep Left: | awk '{print $5}'
Dai_trying
 
Posts: 531
Joined: 2016-01-07 12:25

Re: amixer output problem

Postby pawRoot » 2018-03-12 18:26

This worked, but do you know how to display it without braces ?
Thank you
User avatar
pawRoot
 
Posts: 515
Joined: 2016-12-28 18:26
Location: Poland

Re: amixer output problem

Postby Dai_trying » 2018-03-12 18:46

amixer get Master | grep Left: | awk '{print $5}' | sed 's/[][]//g'

:D
Dai_trying
 
Posts: 531
Joined: 2016-01-07 12:25

Re: amixer output problem

Postby pawRoot » 2018-03-12 18:55

Perfect, thanks :D
User avatar
pawRoot
 
Posts: 515
Joined: 2016-12-28 18:26
Location: Poland

Re: [SOLVED] amixer output problem

Postby Head_on_a_Stick » 2018-03-12 20:06

Or with awk alone and just one pipe:
Code: Select all
amixer get Master | awk -F'[' '/Left:/{gsub("]","");print $2}'

:)

@OP: the trick is to examine the output to be filtered and decide which commands to use to achieve that.

If you run:
Code: Select all
amixer -c 0 get Master

What is the output?

Why were you even trying that when you knew full well that plain `amixer get Master` gives the output you need to filter?
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: [SOLVED] amixer output problem

Postby Dai_trying » 2018-03-12 20:51

I have to say my proposal was definitely not elegant but I was solving one issue at a time when I got to that point and knew it could be achieved more simply (or efficiently) with a different command structure but figured OP could work on that if required. :wink:
Dai_trying
 
Posts: 531
Joined: 2016-01-07 12:25

Re: [SOLVED] amixer output problem

Postby Head_on_a_Stick » 2018-03-12 21:16

^ Yes, indeed, very laudable.

I just can't resist a good game of code golf, that's all :mrgreen:
ESTRAGON: We always find something, eh, Didi, to give us the impression we exist?
VLADIMIR (impatiently): Yes, yes, we're magicians.
User avatar
Head_on_a_Stick
 
Posts: 7893
Joined: 2014-06-01 17:46
Location: /dev/chair

Next

Return to General Questions

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable