As far as the automatic sound change goes a quick look and Ask Ubuntu came up with this answer.
I have not tested this solution but author claims it works with Ubuntu 14.04 meaning it should work with elementary OS Freya as well. All credit goes to him.
Create a file
/etc/udev/rules.d/hdmi_sound.rules as root with the content:
SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/hdmi_sound_toggle"
Create a file
/usr/local/bin/hdmi_sound_toggle as root with the content:
USER_NAME=`who | grep "(:0)" | cut -f 1 -d ' '`
USER_ID=`id -u $USER_NAME`
if [ $HDMI_STATUS = "connected" ]
sudo -u $USER_NAME pactl --server $PULSE_SERVER set-card-profile 0 output:hdmi-stereo+input:analog-stereo
sudo -u $USER_NAME pactl --server $PULSE_SERVER set-card-profile 0 output:analog-stereo+input:analog-stereo
Then make it executable with
chmod 0755 /usr/local/bin/hdmi_sound_toggle
I tried to make this script as generic as possible, but you still might need to change some lines, such as the HDMI_STATUS file path or the profiles used. You can see a list of profiles by running
pactl list cards and looking under Profiles.
Note that the script failed for me when I removed the keyword "export" when setting PULSE_SERVER, I think pactl is looking for the env variable
Don't forget to reload your udev rules:
sudo udevadm control --reload-rules