Issues Lowering Volume of Spotify with AppleScript

Discussion in 'Mac Programming' started by macman7002, Mar 18, 2013.

  1. macrumors regular

    Joined:
    Apr 28, 2008
    #1
    Can anyone help explain why this script doesn't yield the expected result of decreasing Spotify's volume by units of 10? When I run it for iTunes, iTunes will decrease from say 100 to 90 to 80. Any ideas why it doesn't work the same with Spotify, and how I could correct it?

    While we're at it, is there a better way I could rewrite this subroutine?

    Thanks for the help!

    Code:

    Code:
    tell application "Spotify"
    	set currentVolume to sound volume
    end tell
    
    on fadeOut(currentVolume, desiredVolume, delayTime)
    	tell application "Spotify"
    		set currentVolume to sound volume
    		repeat while currentVolume is greater than desiredVolume
    			set sound volume to currentVolume - 10
    			set currentVolume to sound volume
    			delay delayTime
    		end repeat
    	end tell
    	
    end fadeOut
    
    fadeOut(currentVolume, 30, 10)
    
    Response:
    Code:
    tell application "Spotify"
    	get sound volume
    		--> 100
    	get sound volume
    		--> 100
    	set sound volume to 90
    	get sound volume
    		--> 89
    	set sound volume to 79
    	get sound volume
    		--> 78
    	set sound volume to 68
    	get sound volume
    		--> 67
    	set sound volume to 57
    	get sound volume
    		--> 56
    	set sound volume to 46
    	get sound volume
    		--> 45
    
     

Share This Page