Fading iTunes in and out

i found this script on the web for fading out itunes and pausing the player:

tell application “iTunes”
set sound_level to sound volume
set sound volume to 0
play
repeat while sound volume < sound_level
set sound volume to sound volume + 1
end repeat
end tell

it works fine. i tried to create a script to do the opposite, restart the player and fade the volume up to the original level. here’s what i wrote:

tell application “iTunes”
set sound_level to sound volume
set sound volume to 0
play
repeat while sound volume < sound_level
set sound volume to sound volume + 1
end repeat
end tell

it sets the sound volume to 0 and starts playing, but the fade-in never happens. suggestions?

http://foolong.org/archives/2004/02/25/iTunesPlayPause.scpt.zip

this works great. thanks so much. i have one more request. i saved it as an application, and when i double-click to launch it, it gives me a dialog asking me if i want to run it. is there a way to avoid this extra step?

not sure about the dialog box, but wouldn’t it be simpler to place it in your iTunes scripts folder? That way, it will become a menu item under the little script icon when iTunes is the foreground app. You can just select it an it will run.

i figured out the dialog box problem. by unchecking the “startup screen” option when saving the script as an application, the behavior went away.

your suggestion of putting it in the itunes script folder would have made sense if i wanted to use the script that way. but i actually was looking for a script that would run as an appliet when other applications were in the foreground, so that i could invoke it from my griffin powermate. this gives me a way to fade my music out and stop itunes when i have to answer the phone, then restart itunes and fade back in when i hang up. and i never have to change apps or touch the mouse or keyboard. no matter what else i’m doing, i have one big button on my desk to push, and the behavior happens. it’s quite handy, and your script made it possible. thanks again.

Hi. I know it’s 20 years and the link that you posted to doesn’t exist any more. Can you send the script or repost a link here or just send me an email with the script? It’s swooned@gmail.com. Thanks.

By the way, I have found scripts and fix them to work and they run his Apple scripts in Automator but when I make it an application, the fade in part doesn’t work. it doesn’t work even as a script to access through services or quick actions. It’s really infuriating. Any ideas? Thank you.

Hi there, I know it is 20 years, but I wonder if you can help me. I updated the script for Apple Music, and while it works testing it in Automator, the fede in doesn’t work when using it as a standalone app or through Services. It seems it needs time as to trigger over time to fade in. Any ideas? Many thanks.

Add a delay in the repeat loop