Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[SOLVED] amixer output problem

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

[SOLVED] amixer output problem

#1 Post by pawRoot »

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.

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: amixer output problem

#2 Post by Dai_trying »

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%]

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1389
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 66 times

Re: amixer output problem

#3 Post by None1975 »

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 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: amixer output problem

#4 Post by pawRoot »

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 :(

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: amixer output problem

#5 Post by Dai_trying »

and this doesn't work??

Code: Select all

${exec amixer -c 0 get Master | grep Mono: | awk '{ print $4 }'}

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: amixer output problem

#6 Post by pawRoot »

^nope it doesn't display anything :x

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: amixer output problem

#7 Post by Dai_trying »

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.

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: amixer output problem

#8 Post by pawRoot »

Code: Select all

amixer -c 0 get Master | grep Left: | awk '{ print $5 }'
Something like that?

it still gives me same error

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: amixer output problem

#9 Post by Dai_trying »

how about you try this one...

Code: Select all

amixer get Master | grep Left: | awk '{print $5}'

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: amixer output problem

#10 Post by pawRoot »

This worked, but do you know how to display it without braces ?
Thank you

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: amixer output problem

#11 Post by Dai_trying »

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

:D

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: amixer output problem

#12 Post by pawRoot »

Perfect, thanks :D

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [SOLVED] amixer output problem

#13 Post by Head_on_a_Stick »

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?
deadbang

Dai_trying
Posts: 1100
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: [SOLVED] amixer output problem

#14 Post by Dai_trying »

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:

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [SOLVED] amixer output problem

#15 Post by Head_on_a_Stick »

^ Yes, indeed, very laudable.

I just can't resist a good game of code golf, that's all :mrgreen:
deadbang

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: [SOLVED] amixer output problem

#16 Post by pawRoot »

Thanks to you both, HOAS method works aswell.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [SOLVED] amixer output problem

#17 Post by Head_on_a_Stick »

If you plan to use the command in conky then it's best to use as few commands and pipes as possible so as to save on memory usage and processor cycles — conky can use up a significant proportion of your CPU capability if you make it run enough commands every clock tick.
deadbang

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: [SOLVED] amixer output problem

#18 Post by pawRoot »

Here is my config

Code: Select all

out_to_x no
out_to_console yes
update_interval 1

TEXT
  ${mem} / ${memmax}    \
  ${downspeedf enp2s0} / ${upspeedf enp2s0}KiB    \
  ${apcupsd_charge}    \
  ${fs_used} / ${fs_size}    \
  ${exec dpkg --list | wc --lines}    \
  ${time}    \
  ${exec amixer get Master | awk -F'[' '/Left:/{gsub("]","");print $2}'}

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: [SOLVED] amixer output problem

#19 Post by Head_on_a_Stick »

pawRoot wrote:

Code: Select all

${exec dpkg --list | wc --lines}
The output of `dpkg --list` includes some lines not related to installed packages, this will give the correct figure:

Code: Select all

${exec dpkg --list | grep -c ^i}
^ grep can count :)
deadbang

User avatar
pawRoot
Posts: 603
Joined: 2016-12-28 18:26
Has thanked: 1 time
Been thanked: 1 time

Re: [SOLVED] amixer output problem

#20 Post by pawRoot »

^ Thanks 8)

Post Reply