Is there a way to enable the ringer/notification sounds only when using headphones? Let me explain the scenario:

I always keep my phone in vibration mode (no ringer, no notification sounds, just the vibration), since I'm a forgetful person and I'd end up forgetting to turn the ringer off when I'm in a meeting or other occasions when it wouldn't be appropriate.

This works fine for my needs, except in one instance: when listening to music. When I listen to music I typically keep my phone in the pocket of my jacket and I end up missing all my notifications, since between the music and the fact I don't have the phone in my hand or on my desk I can't hear nor feel the vibration.

My question is: is there a way to turn the ringer/notification sound on when the headphones are connected, while keeping it off when they aren't?

I'm running rooted stock Marshmallow (6.0.1)
I don't have Android Marshmallow but following apps can easily achieve the goal on Android Lollipop 5.1. Should not fail on your OS, I believe. Let me know the result in any case.

MacroDroid

When headphones are plugged:


Trigger: Headphones Insert/Remove &rarr; Headphones Inserted
Action: Volume Change &rarr; select Notification and Ringer, and configure the slider for the level of volume you want


When headphones are removed:


Trigger: Headphones Insert/Remove &rarr; Headphones Removed
Action: Volume Change &rarr; select Notification and Ringer, and keep the slider to 0


Automate

It seems to work too. Your flow should look like this:

(Click image to enlarge)



Relevant blocks:


Interface &rarr; Wired headset plugged?
Settings &rarr; Ringer mode set


The said flow would cause the ringer and notification volume to come back to the level you set them to, before switching the phone to vibration.

Atooma

It worked as well. However, it appears to not been updated since May 2015.

When headphones are connected:


IF: Headphone &rarr; Plugged 
DO: Audio Manager &rarr; Set ringer volume &rarr; configure the slider
DO: Audio Manager &rarr; Notification volume &rarr; configure the slider


When headphones are removed:


IF: Headphone &rarr; Unplugged 
DO: Silent mode &rarr; On &rarr; Vibrate: Yes


Droid Automation

It also worked well for me.

Instructions:


Profile: Headset plugged


Trigger: Headset state &rarr; Becomes plugged  
Task: Sounds &amp; Media &rarr; Volume: Ringtones &rarr; configure
Task: Sounds &amp; Media &rarr; Volume: Notifications &rarr; configure

Profile: Headset unplugged


Trigger: Headset state &rarr; Becomes unplugged
Task: Sounds &amp; Media &rarr; Volume: Ringtones &rarr; configure to zero