Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
3,623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- The fadetime in seconds
  2. property fadetime : 3
  3.  
  4. -- The target Volume of the fade 0-100
  5. property targetVolume : 0
  6.  
  7. -- Pause the player when the fade is done true/false
  8. property stopWhenDone : false
  9.  
  10. -----------------------------------------------------------------------------
  11.  
  12. tell application "Spotify"
  13.    
  14.     set deltaVolume to targetVolume - sound volume
  15.    
  16.     if deltaVolume is not equal to 0 then
  17.        
  18.         -- calculate the time for each step to end
  19.         set steptime to fadetime / deltaVolume
  20.        
  21.         -- inc/dec step size
  22.         set step to 1
  23.        
  24.         -- if it is a decrease in volume
  25.         if deltaVolume < 0 then
  26.             set steptime to -steptime
  27.             set step to -step
  28.         end if
  29.        
  30.         -- Do the fade
  31.         repeat with v from sound volume to targetVolume by step
  32.             set sound volume to v
  33.             delay steptime
  34.         end repeat
  35.        
  36.     end if
  37.    
  38.     -- optional stop
  39.     if stopWhenDone then pause
  40.    
  41. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement