Music Volume Control – How to Control Volume Based on ‘Now Playing’ on macOS

automationmacosmusicsound-volumespotify

I'd like the Mac to mute itself when there's an ad on Spotify. It comes in a pair, 30 seconds each. I now have to hit mute button, then guess if a minute is over yet and then unmute it. Solid distraction.

I think that this info: "Advertisement" in music title could be used. But I don't know if it is accessible by any means in AppleScript.

Some task/ process/ job which I turn on while opening Spotify, which would be monitoring the Song title and then trigger mute and unmute after 60 seconds would do.

Please get me started on this.

enter image description here

Best Answer

I figured a simple solution. Saved this script & put it in user scripts folder.

tell application "System Events"
    set volume 0
    delay 30
    set volume 2
end tell

enter image description here