AppleScript: Delay can be used with non-integer values

Feb 20, '04 08:51:00AM

Contributed by: lachdrache

The command delay is available in AppleScript via Standard Additions:

delay: Pause for a fixed amount of time
  delay  number  -- the number of seconds to delay
I wanted to pause my script for a shorter amount of time than one second and tried delay 0.1. To my surprise, it worked! I used this for an iTunes script which fades out the current song and continues with the next song:


tell application "iTunes"
  activate
  set nOldSoundVolume to sound volume
  repeat with nSoundVolume from sound volume to 0 by -1
    set sound volume to nSoundVolume
    delay 0.1
  end repeat
  stop
  next track
  set sound volume to nOldSoundVolume
  play
end tell
Paste this script into Script Editor and save it to ~/Library/iTunes/Scripts. Have fun with iTunes and AppleScript!

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040212081337914