Improve playing a random iTunes playlist from a folder

Discussion in 'AppleScript' started by Didgeridrew, Aug 16, 2018.

  1. Didgeridrew

    Didgeridrew New Member

    Joined:
    Aug 16, 2018
    Messages:
    1
    Likes Received:
    0
    Location:
    West Virginia
    I've been trying to add a little variety (but not too much variety) to my morning music. Previously, I had been using Automator to play a single playlist every morning. But now I am trying to figure out an AppleScript that will chose a random playlist from a folder of playlist named "Morning" and play it in a random order. After some initial success, I've hit a roadblock. My main hurdle seems to be specifying that I want one of the playlists within the playlist folder.

    My first working attempt was as follows:

    Code:
    on run
        set playName to (random number from 1 to 5)
        set morningPlaylist to playName as text
        tell application "iTunes"
            launch
            stop
            set todayPlay to user playlist morningPlaylist
            set view of front window to todayPlay
            set shuffle enabled to true
            play todayPlay
        end tell
    end run
    This meets the basic criteria for what I wanted by working around the folder issue. For future use, I would prefer not to have to name the lists with numbers or modify the script if I add a new playlist.

    To that end I tried:

    Code:
    on run
        set morningPlaylist to "Morning"
        tell application "iTunes"
            activate
            set todayPlay to folder playlist morningPlaylist
            play some track of todayPlay
            set view of front window to todayPlay
            set shuffle enabled to true
        end tell
    end run
    This basically just selects the entire folder and plays a random track then shuffles through all the songs from all the folder... not what I was going for. I've tried a few other things but none seems to work.

    Is there a way to have the script create a list of the playlists in the folder and then choose one of them at random?
    I thought maybe I could use
    Code:
    play some playlist
    but I get the error
    if I try any variation of that. Apparently "some" and "playlist" aren't friends.
     
    Didgeridrew, Aug 16, 2018
    #1
    1. Advertisements

  2. Didgeridrew

    Cory Cooper Moderator

    Joined:
    May 19, 2004
    Messages:
    5,943
    Likes Received:
    193
    Hello and welcome.

    Unfortunately, that is way beyond my experience and knowledge level with Automator/AppleScript. Maybe the folks over at MacScripter could lend a hand.

    C
     
    Cory Cooper, Aug 18, 2018
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.