I often find myself pulling up the pulse audio GUI to flip the output of a specific application between speakers and headphones. I wanted to set up a hot key to toggle where audio from the active application was sent, but as far as I could tell, there wasn’t a way to do that from the command line.
A quick C program was required for communicating with the pulse audio server, and I’ve uploaded that to github.
To toggle the sink for the active application, I’m using this shellscript:
#!/bin/sh
root=`xprop -root _NET_ACTIVE_WINDOW`
activewindow=`echo $root | cut -d" " -f 5`
pidstr=`xprop -id $activewindow _NET_WM_PID`
pid=`echo $pidstr | cut -d" " -f 3`
patogglepid $pid