Mute Optical Output On OS X

This is truely frustrating. Not being able to control the system volume when using optical output I could definitely deal with, IF I could at least mute it. After some Googling I realized this just wasn’t going to happen – at least not without some creative thinking. This solution is not exactly elegant, but, it does work.

I had recently installed Plex which installed SoundFlower. SoundFlower allows you to send all system output to an application for processing (normally, to record or send audio to another computer/device). I don’t use it at all though, so as I expected activating this effectively muted my audio. If you do use it, well, you may need to figure out another way to do this.

So the first step here is if you don’t have SoundFlower installed, go grab it and install it. Now, I like everything to be controled via the keyboard, but if you don’t care about this then don’t worry about the rest of this post. You can change the audio output via the sound menu in your menubar by holding down option when clicking on it.

If you want to control this with a key command, then here goes.

First download this: SwitchAudioSource. I put it in /usr/local/bin, but thats up to you.

Next I wrote a simple Applescript to execute the command. Applescript editor is located at “/Utilities/Applescript Editor”.

If you plan to use Growl notifications, just run this Applescript first, you only need to run it once to register the notifications we’ll be using.

tell application “GrowlHelperApp”
set appName to “System Preferences”
set notificationName to “Sound Muted”
set notifs to {“Sound Muted”, “Sound Un-Muted”}
register as application appName all notifications notifs default notifications notifs
end tell

Next up, save the following script somewhere:

set curOut to (do shell script “/usr/local/bin/SwitchAudioSource -c”)
if (curOut = “Built-in Output”) then
do shell script “/usr/local/bin/SwitchAudioSource -s ‘Soundflower (2ch)'”
set notificationName to “Sound Muted”
set growlString to “Muted”
my pause_itunes()
else
do shell script “/usr/local/bin/SwitchAudioSource -s ‘Built-in Output'”
set notificationName to “Sound Un-Muted”
set growlString to “Un-Muted”
my play_itunes()
end if

tell application “GrowlHelperApp”
set appName to “System Preferences”
notify with name notificationName application name appName title notificationName description growlString
end tell

on pause_itunes()
try
tell application “Finder” to get (every process whose name is “iTunes”)
if result is not {} then — only update when iTunes running
tell application “iTunes”
if player state is playing then
pause
end if
end tell
end if
end try
end pause_itunes

on play_itunes()
try
tell application “Finder” to get (every process whose name is “iTunes”)
if result is not {} then — only update when iTunes running
tell application “iTunes”
if player state is paused then
play
end if
end tell
end if
end try
end play_itunes

As you can see I added a little more to this. The basic stuff is just the do shell script calls to SwitchAudioSource. I added Growl notifications to tell me when this runs, as well as checking with and pausing/playing iTunes when I mute/unmute.

I run this script with a keyboard command thanks to the excellent application Proxi from Griffin. You could even just save it as an application and keep it in your dock if that suits you.

Disclaimer: There is almost certainly a more elegant way to do this, namely it can almost certainly all be accomplished via just the command line, but getting it working in Applescript was the fastest way for me to do it. This runs in less than a second under heavy load on my system, so, it’s a not a problem for me.

Leave a Reply

Your email address will not be published.