Default Disabling the external speaker

Sorry if this is the wrong forum, but I figured it would be useful here. I'm reverse engineering the Blu Studio 5.3 dock port (see this thread in this forum) and have found the audio lines, but they're apparently on the headphone line. Unless the external headphones are plugged in, the phone thinks that it should be playing through the speaker. In order to disable the phone's speaker, I need some kind of an app because it's controlled in software.

I know nothing about coding for android so I'm hoping someone here can, in the hope of helping out a fellow hardware hacker, write a simple program that just toggles all audio between the external speaker and the headphone line.

Thanks in advance.