Output to Speakers or headphones?
Headphone jack sockets include switched contacts for exactly this purpose. See this schematic of a headphone socket:



So you would connect your source to pins 2 &amp; 3, and your speakers to pins 4 and 5. As soon as the headphone is plugged in the speakers are disconnected.