I would like to share with you how I solved this with a permanent solution without scripts. This way we can also get rid of the ugly pop sound when pulseaudio starts.
I use Apple MacBook 7,1 Mid 2010, White Unibody.
The reason why the red light lights up on every pulseaudio start is that there is automatic detection of hardware defined in /etc/pulse/default.pa
The usual default.pa example here: https://gist.github.com/95406ea115dc3a0a561f8242e2ae00f4
### Automatically load driver modules depending on the hardware available
.ifexists module-udev-detect.so
load-module module-udev-detect
.else
### Use the static hardware detection module (for systems that lack udev support)
load-module module-detect
.endif
When these modules are being loaded it automatically detects your hardware and also initializes it. While the hardware is being initialized then SPDI/F output is turned on so red light is glowing even if you previously toggled mute using alsamixser off. When SPDI/F are toggled again on then there is also the ugly pop sound effect.
To avoid this behavior I decided to define my hardware manually.
I don't wan't use automatic hardware detection modules. I disabled them by commenting whole block:
### Automatically load driver modules depending on the hardware available
#.ifexists module-udev-detect.so
#load-module module-udev-detect
#.else
### Use the static hardware detection module (for systems that lack udev support)
#load-module module-detect
#.endif
Now, I need to define my audio hardware - output sink and input source.
I have used module-alsa-sink and module-alsa-source. I also need to know which HW ID's my audio sources have. On my machine there is only one integrated audio card with both input/output which has id hw:0,0. It can be different on your machine.
This is how I load outpit sink and input source modules:
### Load audio drivers statically
load-module module-alsa-sink device=hw:0,0
load-module module-alsa-source device=hw:0,0
#load-module module-null-sink
#load-module module-pipe-sink
It's important to reload pulseaudio then.
You can use: pulseaudio --vv --kill and then again start it with
pulseaudio --vv --start
No we will have available both our audio input/output, the jack isn't glowing with the red and the pop sound on startup is gone. All changes made in alsamixer will always persist too.
But, with this simple configurations we can't now use SPDI/F as regular output.
What if decide to play sound through it?
I can even define the SPDI/F output too. The SPDI/F has hw0,1 ID on machine. If I would like to use it again. I will add this line to my configuration:
### Load audio drivers statically
load-module module-alsa-sink device=hw:0,0
load-module module-alsa-sink device=hw:0,1
load-module module-alsa-source device=hw:0,0
#load-module module-null-sink
#load-module module-pipe-sink
With this configuration we can easily disable and enable it in alsamixer. And the configuration will persist.
Here is sample of my configuration I use: https://gist.github.com/7a11adf0edc49d55a60be071ca307784
Actually, I don't own any other kind of sound system so I'm not able to test it with it. If you are using 2.1 or 4.1 sound system the output will be probably played only as stereo and you will need add more configurations in order to get it properly work. The same problem could be with HDMI outpout, I can't test it.