Для ubuntu-16.10 я сделал несколько изменений в этом ответе.
oldresult="Some Random String"
while [ 1 ]; do
# incase of plugged out result will contain some data
result=$(grep "EAPD 0x2: EAPD" /proc/asound/card0/codec#0)
# checking for oldresult if not same then only go inside
if [ "$oldresult" != "$result" ]; then
oldresult=$result
if [[ -z "$result" ]]; then
notify-send "Plugged In"
amixer sset Master playback 80% # Set volume to 80%
else
notify-send "Plugged Out"
amixer sset Master playback 0% # Set volume to 0%
fi
fi
done