According to this answer , information can be gathered from the files /proc/asound/card*/codec#* .
An example from this answer:
headphones connected:
 $ cat /proc/asound/card0/codec#0 [...] Node 0x0d [Pin Complex] wcaps 0x400181: Stereo Control: name="Speaker Phantom Jack", index=0, device=0 Pincap 0x00000014: OUT Detect Pin Default 0x90170110: [Fixed] Speaker at Int N/A Conn = Analog, Color = Unknown DefAssociation = 0x1, Sequence = 0x0 Misc = NO_PRESENCE Pin-ctls: 0x00: [...] 
Headphones are disabled (compare the lines about Pin-ctls ):
 $ cat /proc/asound/card0/codec#0 [...] Node 0x0d [Pin Complex] wcaps 0x400181: Stereo Control: name="Speaker Phantom Jack", index=0, device=0 Pincap 0x00000014: OUT Detect Pin Default 0x90170110: [Fixed] Speaker at Int N/A Conn = Analog, Color = Unknown DefAssociation = 0x1, Sequence = 0x0 Misc = NO_PRESENCE Pin-ctls: 0x40: OUT [...]