I've written a simple script to alternate audio out between my laptop speakers and phone out. This script is intended for scrotwm, but also can be used on its own.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My scrotwm config | |
# Programs | |
program[swap_audio] = /usr/local/share/scrotwm/audioout.sh | |
# Key Bindings | |
bind[swap_audio] = MOD+Shift+a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# audioout.sh - Ahmad Zulkarnain 08/09/11 | |
# Script to alternate between audio master output and phone output. | |
# Will be used by scrotwm. Copy to /usr/local/share/scrotwm/ | |
# and alter ~/.scrotwm.conf accordingly. | |
# Variables for audio status | |
master=$(mixerctl | grep master.mute | sed s/.*=//) | |
phout=$(mixerctl | grep phone.mute | sed s/.*=//) | |
# Program starts | |
if [[ $master == 'on' ]]; | |
then | |
mixerctl outputs.master.mute=off; | |
mixerctl outputs.hp.mute=on; | |
elif [[ $phout == 'on' ]]; | |
then | |
mixerctl outputs.master.mute=on; | |
mixerctl outputs.hp.mute=off; | |
else | |
mixerctl outputs.master.mute=off; | |
mixerctl outputs.hp.mute=on; | |
fi |
As usual, feel free to copy this file and improve it. You can see by the Gist that there's 2 files, the first is .scrotwm.conf and the next one is audioout.sh (see the file name on bottom right of the embed).
The .scrotwm.conf is a snippet of configuration needed to make the script work with scrotwm's key binding. As you can see, I've set the key binding to Mod+Shift+a key. So whenever I press the key binding, the audio output will swap between speaker and phone out. Very simple. All I need to do is add the snippet to ~/.scrotwm.conf.
Then I need to save the 2nd file as audioout.sh and save it in /usr/local/share/scrotwm/. There's a few other default scrotwm's script inside there. Make sure the audioout.sh is executable, if not do chmod 755 or similar which is suitable for your environment. Then enjoy.
Previously I would need to manually mute/unmute both master and phone out as I sometime uses headphone. Now I can simply press Mod+Shift+a to swap between it.
Take note that this script can be used even without scrotwm. You just need to copy the 2nd file to your ~/ (home) and run it by typing ./audioout.sh or use another keybinding if available. Later.