I think that the best way to do this is with this addon written by Greg Zaal, see this post.
However, after fiddling around a bit I found that the active material output node is the one that has not been selected for the longest time.
For example, say that the red shader (by shader I mean the material output node) is currently active in a node setup like this:

To make the green material output active:
Select the green material output
Select the blue material output again, so the green shader has now been unselected for the longest (not counting the red shader).
Select the red shader. The green material output will now be active.
To make the blue material output active:
- Select the green shader
- Select the red shader (the currently active material output). The currently active shader is now the blue material output.