» pages: blog | About Me | projects | Resume |

toggle headphones/speakers key via xbindkeys

linux — davidb — December 5th, 2008

I’ve been using xbindkeys for a few years now to create keyboard shortcuts on my computer. It’s super useful, and a quite easy way to get the multimedia keys on my keyboard to do what I want. A quick tutorial on xbindkeys:

First, install it

sudo apt-get install xbindkeys

Then, run the following in a console to grab input for a specific key press combination.

xbindkeys -mk

Select the window that pops up, type the key, and on the console you should see some output something like this:

"(Scheme function)"
    m:0x10 + c:98
    Mod2 + Up

Copy and paste that into your .xbindkeysrc and change “(Scheme function)” to “foo” where foo is the command you would like executed. Quit that, run xbindkeys, and whenever you type that key combination, foo will be executed.

So, a few months ago I bought a pair of 2.1 speakers for my computer. In the past I’ve only used headphones, so being able to lie in bed and watch movies/listen to music was very nice. However, I tend to work late into the night and my room mates don’t exactly appreciate my loud music. So, I still use headphones occasionally. The problem is I don’t want to have to unplug the speakers and plug them back in every time I want to use headphones. Luckily, my sound card has multiple line outs. So, a combination of amixer and xbindkeys allows me to simply hit a button on my keyboard to switch between the headphones and the speakers.

Here’s the snippet of my .xbindkeysrc that does this work:

# favorites button - toggle headphones/speakers
"amixer set Surround toggle; amixer set Front toggle"
m:0x10 + c:230
Mod2 + NoSymbol

2 Comments »

  1. Hi, I do not have Surround in my amixer? How to get it? Want to toggle the headphones to speakers or front to back for Voip with a quick hotkey. Thanks

    Comment by jans — April 18, 2010 @ 10:28 pm
  2. You’re going to have to look at what channels/mixer controls you do have available in amixer. Additionally you may want to look at the manual for your motherboard/sound card to make sure it’s possible. Some motherboards/sound cards mute the other outputs if you plug in headphones.

    For testing, plug both your headphones and speakers in and run alsamixer in a terminal. Adjust the different mixer controls (muting/changing volume) until you find which one controls the headphones and which one controls the speakers. Then use these instead of “Surround.”

    Comment by davidb — April 19, 2010 @ 2:39 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

(c) 2010 david-brenner.net | powered by WordPress with Barecity