1

I'd like to write a Shortcut ("Fade out Apple Music") that slowly reduces the Apple Music volume over the course of ~5 seconds.

I don't see a Shortcut option for getting/setting Apple Music's volume, so I figure that AppleScript would be the right choice - but I am not familiar enough with AppleScript to know what variables/syntax to use for it.

How can I get/set the volume of Apple Music? (As a bonus: how can I write a little loop to adjust the volume over the course of 5 seconds?)

Essentially, that'd be the equivalent of slowly adjusting this slider down to zero: Screenshot of Apple Music, with the volume indicator highlighted

1 Answer 1

3

Alright, I figured out a simple script that does what I want! You can adjust the parameters in the first two lines to "tune" it to what you want - but I think this is a pretty-nicely-tuned setup. It slowly steps-down the volume to create a fadeout, which is nice when you're DJing the Zoom call and want a subtle fadeout effect.

set fadeDuration to 3 -- in seconds


tell application "Music"
    set currentVolume to sound volume
    
    if currentVolume > 0 then
        set fadeStepDuration to 0.02 -- in seconds, Apple says this should be > 0.01667
        set fadeStepCount to fadeDuration / fadeStepDuration
        set fadeStepSize to currentVolume / fadeStepCount
        
        repeat fadeStepCount times
            set currentVolume to currentVolume - fadeStepSize
            set sound volume to currentVolume
            delay fadeStepDuration
        end repeat
    end if
    
end tell

Here's how it looks in action: volume fade-out in action

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .