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.