there is NO hardware to detect, the OS can only detect the speaker socket, not whether it is connected, it is an analog channel not a readable port (usb firewire).
laptop settings are very specific to the laptop, the item below may be totally wrong, but of you hunt thru control panel.....there...