1

I like having a hotkey to bring up the get info box for the current iTunes track so that if I'm using another app and a song comes up, I can quickly edit it. This works (though if it's not the best way, please let me know):

tell application "iTunes"
    activate
    reveal current track
end tell
tell application "System Events"
    tell process "iTunes"
        key code 34 using command down
    end tell
end tell

I've assigned that a hotkey in BetterTouchTool and it's great.

I'd like to have a version of that script to edit the previous song... but changing "current track" to "previous track" causes a completely different result. iTunes goes back to play the previous track again even though I only told it to reveal it, and then I get an error saying applescript can't continue reveal.

tell application "iTunes"
    activate
    reveal (previous track)
end tell

What's the easiest way to get iTunes to show the previous track in a playlist using Applescript?

1

You can in a round about way using the "Recently Played" playlist.

You configure it the way you want, I've set it to the 5 most recent items, and then run this code...

tell application "iTunes"
    set rp to get playlist "Recently Played"
    #get name of every track of rp
    #get name of last track of rp
    #set tid to get id of last track of rp
    reveal track 5 of rp

    activate

    tell application "System Events"
        tell process "iTunes"
            key code 34 using command down
        end tell
    end tell        
end tell

Hope this helped.

EDIT: This only works with songs that are fully played. Partially played tracks will not show up in the "Recently Played".

  • If, by Recently Played, you mean a smart playlist... I deleted that long ago for exactly the reason you mentioned. Partially played tracks don't show up there, which I find frustrating. Hhhmmmm... I may need to think about an alternate approach, such as logging all songs played? Or something? I love being able to automate things, but I want those solutions to always work. I skip around in iTunes often enough that the recently played column isn't always helpful. I wish I could create a smart playlist with everything played or skipped listed chronologically. – 2oh1 Dec 11 '14 at 20:17
  • Yes a smart playlist. Alternatively, like you said, you can write a script to constantly query the song played and log it somewhere and use that to go back. It would be easy enough to write. It is also possible to be notified of events from itunes but you would have to write a cocoa app. – Vic Dec 14 '14 at 18:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .