AppleScript Previous Track

Discussion in 'Mac Programming' started by wrignj08, Aug 15, 2013.

  1. macrumors newbie

    Joined:
    Jun 13, 2009
    #1
    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 :)
     
  2. macrumors 68040

    Joined:
    Feb 2, 2008
    #2
    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?
     
  3. thread starter macrumors newbie

    Joined:
    Jun 13, 2009
    #3
    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.
     
  4. thread starter macrumors newbie

    Joined:
    Jun 13, 2009
    #4
    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
     
  5. macrumors 68030

    tkermit

    Joined:
    Feb 20, 2004
    #5
    Code:
    tell app "iTunes" to back track
    ;)
     
  6. thread starter macrumors newbie

    Joined:
    Jun 13, 2009
    #6
    Hahaha thanks Mate that would have saved some time :)
     

Share This Page