How to automatically change volume level when un-/plugging headphones?

Solution 1:

During the UDS for Oneiric there has been a session about jack detection. See the blueprint for details. It sounds like this will exactly do what I'm looking for: different volume levels for different devices - just not on every hardware:

<htorque> something i'm curious about: will i be able to have different volume levels for different devices (eg., internal sound muted, headphones 75%) anytime soon?

<coling> this will be supported (on some h/w) yes. Timescales are "soonish" :p
<coling> (I'd also expect OSD to be shown (with current volume) when jacks are plugged/unplugged)

Update for 11.10

This should now be working in Oneiric - unfortunately my ThinkPad T510 seems to be one of the systems that's currently not supported.

Another follow-up from David Henningsson:

Long story short, it’s a desirable feature, and we’re moving in that direction, but slowly, as the feature is more complex than it seems like at first glance.

The good news: in the upcoming Ubuntu Oneiric (11.10), this is actually working. The bad news: it isn’t working for everyone.

More here.

Update for 12.04

It's now working with my ThinkPad T510 (and many other models) in Ubuntu 12.04 (development version).

Solution 2:

To set volume level from console use the command amixer. For example:

amixer sset Master playback 0%

Will set your level to 0%

I don't know how to change this when you plug in your headphones... but maybe someone can help you with that

Solution 3:

Ear Candy has some functionality for dealing with headphone insertion/removal.