I have written a couple of simple scripts that can switch the speakers and headphones and thought I share it. Pretty straightforward though, but maybe it can be updated to be written in one script and can detect whether the auxiliary port is connected to an auxiliary cable or not.
headphones.sh
speakers.sh
headphones.sh
Code:
#!/bin/sh
amixer -c 0 set 'Headphone' unmute
amixer -c 0 set 'Line Out' mute
speakers.sh
Code:
#!/bin/sh
amixer -c 0 set 'Headphone' mute
amixer -c 0 set 'Line Out' unmute