Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

AppleScript: Delay can be used with non-integer values System

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!
    •    
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[45,196 views]  

AppleScript: Delay can be used with non-integer values | 6 comments | Create New Account
Click here to return to the 'AppleScript: Delay can be used with non-integer values' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript: Delay can be used with non-integer values
Authored by: Tom Robinson on Feb 20, '04 01:27:30PM

FYI, that ability came in with AppleScript 1.9.2 / OS X 10.3.



[ Reply to This | # ]
AppleScript: Delay can be used with non-integer values
Authored by: billearl on Feb 21, '04 01:21:43PM

It was listed in the release notes.



[ Reply to This | # ]
AppleScript: Delay can be used with non-integer values
Authored by: floop on Feb 20, '04 10:56:59PM

Thanks for the tip. I needed this a while back and gave up on it. It would not have occurred to me to try it again without reading this.



[ Reply to This | # ]
AppleScript: Delay can be used with non-integer values
Authored by: Cantus on Feb 21, '04 01:43:24AM

You can even use 0.01 for a faster fade out :)

I've been using this delay feature for quite some time in other scripts.



[ Reply to This | # ]
Increase your Play Count
Authored by: thavron on Feb 22, '04 04:42:45PM
If you want to also increase the play count of that song, use this code:
	set player position to (duration of current track) - 1
	delay 1
instead of that stop/start business.

[ Reply to This | # ]
AppleScript: Delay can be used with non-integer values
Authored by: rulerk on Feb 22, '04 05:50:18PM
I quite like this script that fades to the next song, but I also use this modification to the script to fade to the currently selected (rather than just 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
	play selection
	set sound volume to nOldSoundVolume
	play
end tell
Enjoy!

[ Reply to This | # ]