4

I'm running Ubuntu 14.04 and it would be helpful if I can do this. My phone can do it, my laptop should be able to!

2

1 Answer 1

2

Based on the answer given in the link in Glutanimate's comment, I've written this script that partially does the job.

#!/bin/bash
# nm sets this values
INTERFACE=$1
ACTION=$2

SSID="myworkssid"
ESSID=`nm-tool |grep --only-matching '*[^ ][^:]*' |sed 's/^*//'`

if [ "$INTERFACE" = "wlan0" ]
  then
   if [ "$SSID" = "$ESSID" ] &&  [ "$ACTION" = "up" ]
    then 
    #Mute
        amixer -c 0 set Master playback 0% mute
   else
     #unmute
        amixer -c 0 set Master playback 100% unmute
   fi
fi

It has to be copied to /etc/NetworkManager/dispatcher.d/ and it has to be executable and owned by root, based on this link.

However, this script only partially does the job because the unmute command doesn't work. If someone can figure out a way to unmute, I'd be grateful.

3
  • Option 1: amixer set Master toggle. Option 2: amixer sset Master unmute; amixer sset PCM unmute; amixer sset "Master Mono" unmute. Option 3: use pactl instead. pactl set-sink-mute 0 1; pactl set-sink-mute 0 0. Sources: askubuntu.com/questions/258580/…; techytalk.info/…; arvydas.co.uk/2012/08/… Mar 11, 2015 at 15:28
  • I've tried quite a few options with amixer. None of them work. The terminal output is as expected, but the sound output remains muted. I'll try pactl and get back to you!
    – bldysabba
    Mar 12, 2015 at 7:08
  • I hear that problem with amixer is it has many channels and no single unmute (at least none I know of!). :-) Thus I offered toggle. And pactl, in case it doesn't toggle. ;-) Hope this will help. If it will, feel free to incorporate it in your reply. I've upvoted it already. Mar 12, 2015 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .