It's insane that in 2016 we still have to do with this, but since upgrading to El Capitan, previous solutions don't seem to work for me anymore. This is what I've tried.
silence.sh
sudo nvram SystemAudioVolume="%00" # does nothing
osascript -e 'set volume with output muted'
echo "run at $(date)" >> /var/log/silence_log.txt
1. LogoutHook
This is what worked on Yosemite
sudo defaults write com.apple.loginwindow LogoutHook /path/to/silence.sh
but ceased to work on my almost fresh El Capitan install
2. LaunchAgent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
<key>Label</key>
<string>Silence</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/silence.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
But running launchctl load silence_sysvol.plist
doesn't write anything to the log, so the script doesn't seem to run and I haven't figured out how to have it always be loaded and run at logout.
I read that launchd
will send SIGTERM
to the agents on logout, so would something like this be a way to go?
#!/usr/bin/env bash
function silence()
{
sudo nvram SystemAudioVolume="%00" # not working
osascript -e 'set volume with output muted'
echo "run at $(date)" >> /var/log/silence_log.txt
}
trap silence SIGTERM
silence
3. nobootsound
Tried this, didn't work.
Best Answer
After a (few) restart(s), method 1 is back to working. Beats me.