How do I detect if headphones are connected (via the jack) in bash? I have a script, and I want it to behave differently if headphones are connected. How can I get this information?
I tried using SwitchAudioSource, but its output is the same, whether or not the headphones are connected:
~/tmp
❯ SwitchAudioSource -c
Built-in Output

~/tmp
❯ SwitchAudioSource -a
Built-in Microphone (input)
Background Music (input)
Background Music (UI Sounds) (input)
Built-in Output (output)
Background Music (output)
Background Music (UI Sounds) (output)
I found an answer from here:
if system_profiler SPAudioDataType | grep --quiet Headphones; then
  echo plugged in
else
  echo not plugged in
fi