Quit / open an app whenever audio output is changed on mac


I'm using Boom as an equalizer and a File Audio Boosting on my MBP when using built-in speakers. But when using a home device (with an amplifier connected by jack to the MBP) or a headphone (bluetooth or jack) I prefer to disconnect Boom.

So far I have made an automator script that connect/disconnect bluetooth and quit/launch Boom.

Is there a way to upgrade my current script to be triggered with plugging/unplugging of jack or connecting/disconnecting with bluetooth device (not only when activating/disactivating bluetooth)?

Note : I'm aware of Breakaway that Automatically disable speakers when headphones are removed (but only by manually connect/disconnect the jack), but something that quit/launch a specific app will suit me better.

For the curious, here my current script using Blueutil :

set BT to do shell script "/usr/local/bin/blueutil -p"

if BT is equal to "0" then
    do shell script "/usr/local/bin/blueutil -p 1"
    tell application "Boom 2" to quit
    do shell script "/usr/local/bin/blueutil -p 0"
    tell application "Boom 2" to activate
end if

Best Answer

Well, many thanks to CJK for the explanations!

After some struggle with Keyboard Maestro (because of how Boom is made, a Boom2device appears in the sound output devices and never really changes, so the trigger from Keyboard Maestro doesn't work...) I tried user3439894's solution and got Eventscripts to work in less than 10 minutes!

The real plus with EventScripts is that you can choose which Bluetooth devices trigger the AppleScript.

Here's my set up:

enter image description here

With some scripts easy as:

  • Quit Boom:

    quit application "Boom 2" 


  • Activate Boom:

    tell application "Finder"
        open application file "Boom 2.app" of folder "Applications" of startup disk
    end tell

I also made another one that came in my mind to adjust the brightness of the screen after plugging the MBP to the power with brightness.