How can I automatically mute my laptop when it connects to my work wifi network?

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.