PDA

View Full Version : AppleScript Previous Track




wrignj08
Aug 16, 2013, 12:29 AM
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 :)



subsonix
Aug 16, 2013, 01:13 AM
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?

wrignj08
Aug 16, 2013, 01:23 AM
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.

wrignj08
Aug 16, 2013, 02:42 AM
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

tkermit
Aug 16, 2013, 03:44 AM
can anyone simplify it?

tell app "iTunes" to back track ;)

wrignj08
Aug 16, 2013, 03:46 AM
Hahaha thanks Mate that would have saved some time :)