Audio Port

I have a script that I would like to set an if/then/else condition to interpret the condition if something is plugged into my audio port or not, i.e., if something is plugged into my audio jack, play at volume X, if not, play at volume Y.

This is because I use my MacBook Pro for my desktop and when I do I use a plug in audio amplifier and speakers so the volume is set one way to be just right for my desktop setup. When my laptop is away from my desk and only the natural sound level of the laptop is output, the output volume needs to be increased. Or, if I left the output volume set to a higher volume after being away from my desktop, I don't want my desktop amplified setup to blast my ears.

I am not seeing a way of identifying if something is plugged into my audio jack or not.

I know there is a trigger condition that will determine the condition of the audio port, but I am not seeing a way to make use of this as a trigger as I am looking for something that checks this condition in an if/then/else statement within a script.

Ongoing appreciation for the assist.

Have you tried this idea:


and in the second window you have to put the name of your device (I have no idea what it might be) as it appears in the output of the ioreg command from inside a terminal window.

It seems like this might work but to be honest this is just an idea, not a solution. I discovered ioreg only a couple of days ago.