Unfortunately I do not know how to achieve that via command line. On the other hand, it should not be necessary to do that after every reboot, so we should try to fix the underlying problem.
One possibility that comes to mind is that the digital output is muted by default and that choosing both output configurations after one another, all the corresponding outputs are enabled/unmuted. So, we could try to get rid of the problem, so that you do not need to go through this process of choosing both outputs at all.
When you boot your computer, which sound do you normally have? Normal menu sounds out of your speaker, but the digital output does not give you any sound? To test this, there are several ways to go, depending on whether you want to use command line or not.
Without command line you could do this:
First, we probably need to install an ALSA Mixer GUI:
1. Go to Applications > Ubuntu Software Center
2. In the search box in the upper right corner enter "GNOME ALSA Mixer"
3. It will show the GNOME ALSA Mixer now. Select it and click "Install"
4. After installation, start it by going to Applications > Sound & Video > GNOME ALSA Mixer
5. At the top you might have several tabs, one for every sound device. Choose the sound device where you want to enable S/PDIF
6. At the bottom there should be an option named IEC958, which is probably disabled. Enable it.
Try if this will work, even after a reboot.
If you want to do this with command line, you can do this like this:
First, you might need to install the alsa-utils (I am not sure if they are already installed or not):
now you can start the alsamixer in command line:
sudo apt-get install alsa-utils
1. You can use F6 to select your sound device (might be already selected)
2. Use your left/right arrow keys to go to S/PDIF (which probably shows "MM")
3. press 'm' (This should change it from "MM" to "00" and turn green)
Test if this works, even after reboot.