Skip to content

Instantly share code, notes, and snippets.

@mirka
Created April 2, 2011 12:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirka/899458 to your computer and use it in GitHub Desktop.
Save mirka/899458 to your computer and use it in GitHub Desktop.
property resolution : 10 (* Increase for smoother fades. Default: 10 *)
property delayIncr : 0.2 (* Decrease for faster fades. Default: 0.2 *)
tell application "iTunes"
set originalVol to sound volume
set volIncr to originalVol div resolution
if player state is not playing then
set sound volume to 0
play
-- Fade in
repeat while (sound volume ≤ (originalVol - volIncr))
set sound volume to (sound volume + volIncr)
delay delayIncr
end repeat
else
-- Fade out
repeat while (sound volume > 0)
set sound volume to (sound volume - volIncr)
delay delayIncr
end repeat
pause
end if
set sound volume to originalVol
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment