Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wrignj08

macrumors newbie
Original poster
Jun 13, 2009
28
0
Hi All

I just need a little help, when in iTunes if you are to hit the previous track button (and the current song has been playing for more than 2 seconds) the current song will restart. However if the current song has not yet been playing for 2 seconds and you hit the previous track button the previous track will start playing. How can i replicate this in AppleScript?

Thanks :)
 
Hi All

I just need a little help, when in iTunes if you are to hit the previous track button (and the current song has been playing for more than 2 seconds) the current song will restart. However if the current song has not yet been playing for 2 seconds and you hit the previous track button the previous track will start playing. How can i replicate this in AppleScript?

Thanks :)

Where do you want this to happen? I don't quite follow what it is you want to do, per your description iTunes already have this behavior. So you want to use AppleScript to replicate this where?
 
Everywhere, i'm assigning it to a keystroke, if you want the full story here it is.
Ok so i'm sick of being in iPhoto and hitting the media keys intending to control iTunes but iPhoto grabs the keystrokes and starts a slideshow. So to get around this i'm using the functionflip pref pain to turn the "previous", "play/pause" and "next" keys in to F7, F8 and F9 keys. Then i'm using FastScript.app to assign the F7, F8 and F9 key to AppleScripts such as

F8 = tell application "iTunes" to playpause

F9 = tell application "iTunes"
next track
end tell

The problem is that F7 is more tricky

tell application "iTunes"
previous track
end tell

does not work because it does not check the current playback position.
 
Ok so I just put this together and it works :) can anyone simplify it?

tell application "iTunes"
if current track exists then
if player position is less than 2 then
tell application "iTunes"
previous track
end tell
else
set player position to 0
end if
end if
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.