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).

Category: Downloads, OS X, Programming, Software 21 comments »

21 Responses to “NoodleLabs: Fix for Mac Pro headphone behavior”

  1. Anghell

    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

    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

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

  4. orta

    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

    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

    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

    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

    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

    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

    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

    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

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

  13. Kazuo

    however, please note that this separation of audio out and headphones is great for some laptop music based work.

  14. tino

    works thanks!

  15. Jimmy Lee

    Hi Noodle,

    As they say, you cant please every1 (LOL). I actually like the option to leave the headphone/line out plugged in and be able to select internal speakers or headphone. I am on an iMac and it is a pain trying to plug in the headphone everytime I want to use it and then unplugging it again when I finish. This is because the iMac will automatically switch to headphone when it’s plugged in and back to internal speakers when unplugged. Do you know any method that allows me to do leave the headphone plugged in? Thanks for your help.

  16. s farnell

    Thanks for the reference to Soundsource. I gets the job done nicely.

  17. fens

    Studio’s headphone cable features a compact connector design which reduces bulk and eases unnecessary strain that can damage headphone connectors and ports.

  18. mocca

    I really enjoy reading your blog,This information really useful for me.I like individuals that spend time to add new content to their blogs and web sites thanks.

  19. Donovan Keith

    Thanks for posting this script, and also posting a link to SoundSource. I’m consistently impressed by the quality of the the implementation of small free Mac utilities.

  20. Slipp D.

    Although SoundSource has been discontinued for Mountain Lion/10.8, your fix continues to work. Big thanks.

  21. Zendicon

    Thanks so much, I’m glad to see this still works for Lion. Thank you so much for sharing your work!!


Leave a Reply



Back to top