NoodleLabs: Fix for Mac Pro headphone behavior

I’ve done it. I’ve joined the 8-core club. Historically, I always shoot for the sweet spot in terms of price/performance but this time I thought I’d splurge for once and get the octocore (or is it octacore?) Mac Pro. Realistically, it’s a bit overkill. Sure, Hazel now compiles 5x faster but it’s not like I’m doing full builds all the time and it didn’t take all that long before either. Nonetheless, it’s a great machine. There’s one thing about it that bugs me, though.

On my Powermac, when I plug in headphones, it automatically switches sound output to them, even if I have external speakers connected to line-out. Basically, the headphones, internal speaker and line-out are treated as three devices sharing a channel. To me, it makes sense. If I plug in my headphones, it’s because I want to listen through them. If I pull them out, it’s because I want audio to go back through the speakers. Most every piece of consumer audio equipment I’ve used operates like this.

On the Mac Pro, that has changed. The line-out is a separate output and is unaffected when you plug in headphones. So, if you are using external speakers, you have to go into System Preferences and manually change the output audio device to headphones. You could use something like Rogue Amoeba’s SoundSource to switch output devices in a more convenient fashion but nonetheless it’s a manual process. This Apple doc describes the change but it sounds like an engineering decision imposing itself on the user. I don’t care if it’s now orthogonal and consistent; I want it to be useful.

Well, the nice thing about being a programmer is that you can solve the problem yourself. So, I went ahead and created headphoned (read it as “headphone-d” like a unix daemon). All it does is sit there and watch for when the headphones are plugged in, at which point it switches audio output automatically. When the headphones are unplugged, output reverts back to whatever device was selected before.

I’ve never touched the CoreAudio API before so please excuse the naiveté of the implementation. Suggestions and improvements are most welcome. A big thanks to Vincent Gable, author of IMLocation for this article which gave me a big headstart.

There seems to be a problem where the audio will wedge when plugging/unplugging. I found that updating with Apple’s recent audio fix got rid of the problem (or maybe it’s wishful thinking on my part but I haven’t experienced it since). If you find it does happen, just plug the headphones in/out again as that usually unwedges things. Also let me know if you experience this even after updating with Apple’s fix.

And, of course, it’s free (MIT License). Do what you will. It’s a bit rough around the edges (no automatic install), but I figure if you are using a Mac Pro, you are less daunted by the command-line. I’ve included a launchd config. Install it in ~/Library/LaunchDaemons and edit it to reflect where you put the executable. Note that it doesn’t seem to work if it runs as root (I think it needs to run as the console user), so don’t bother installing it at the top level LaunchDaemons directories.

Enjoy.

Download headphoned-1.0.zip

Update [Sep. 5, 2007]:

Rogue Amoeba has now integrated this functionality into SoundSource. The announcement is here. You can grab it from their freebies page (and yes, it is free).

12 Comments »

  1. Anghell Said,

    July 18, 2007 @ 10:32 am

    Hi there,

    I have recently also became the proud owner of a Mac Pro and find myself very much annoyed with the headphone/speaker ‘feature’. So I was very happy when I found this useful program. However, upon opening the ZIP file, I could not find an executable there. Is there a possibility of you uploading another version of the ZIP with an executable present?

    Thanks in advance

  2. mr_noodle Said,

    July 18, 2007 @ 2:05 pm

    Sorry about that. I’ve re-uploaded with an Intel binary included in the package. Let me know if it works for you.

  3. Anghell Said,

    July 19, 2007 @ 4:52 pm

    Yeah, works like a charm now! Thanks a million, takes care of this incredible annoyance

  4. orta Said,

    July 26, 2007 @ 8:17 pm

    I just bought a USB adaptor for mic and headphones, it’s a solution that also works in Windows. Wish that’d existed a few months back :)

  5. Ramón Said,

    August 1, 2007 @ 7:42 pm

    Hi,

    For me it does not work :(

    It does switch to headphones, but it does not switch back to the previous source (I have SoundSource installed, do they conflict?). Sometimes it switches to the internal speaker instead of the line out (which is where I have my speakers connected to).

    So could you write a modification to the software that just switches back an forth between “headphones” and “line out”, reagardless of the previous choice?

    Thanks bunches

  6. Tony Said,

    August 8, 2007 @ 12:50 am

    Hi,

    First, just want to thanks for the app.

    Unfortunately, it does not work for me. It swtiches the output to the heaphoned jack when one is plugged in, but it also plays on the lineout jack.

  7. mr_noodle Said,

    August 8, 2007 @ 9:04 pm

    Ramón: I’ll look into it though I’m a bit busy at the moment. Also, have you tried it without SoundSource installed?

    Tony: Does it also behave this way when you switch manually in System Preferences? I haven’t seen the behavior of output going to two different places.

  8. Tony Said,

    August 11, 2007 @ 10:32 am

    Mr. Noodle - I am running a Mac Pro 2.66, with os x 10.4.10.

    When playing back a file with VLC:

    Speaker Output - Line Out, Volume Control via KB works fine.
    Plug in headphones on front jack, output via line out is still playing, but now volume control adjust the heaphones, and no sound output to the headphones from the file currently being plaed by VLC. I hear command tones from the headphones, when I adjust voulme level.

  9. mr_noodle Said,

    September 5, 2007 @ 4:43 pm

    Check the update I just posted above. Rogue Amoeba has integrated this into SoundSource so you may want to try that out and see if it fixes any of the problems you guys are seeing. Sorry about the late reply but I couldn’t really say anything about it until it got released.

    If you are still seeing problems with it, let me know. Also, make sure to try it with other apps besides VLC.

  10. Shannon Hendrix Said,

    October 13, 2007 @ 12:43 am

    SoundSource is free, and it does automatic switching between headphones and line out.

    I’m not sure why it says it is manual above, unless earlier versions didn’t support the automatic switching.

    Anyway, I use it, and it works great.

  11. mr_noodle Said,

    October 13, 2007 @ 10:16 am

    SoundSource added the headphone autoswitch feature in response to this article (and I even assisted them in the integration of the code). Maybe you missed the update at the bottom of the article that mentions this?

  12. Nicolas Said,

    April 18, 2008 @ 3:54 pm

    You are a god. Nice work! This is great, solved my problem.

RSS feed for comments on this post

Leave a Comment

- Why ask? This confirms you are a human user!