iTunes playlist

Discussion in 'Mac Apps and Mac App Store' started by powerdave, Jun 9, 2004.

  1. powerdave macrumors regular

    Joined:
    Apr 24, 2004
    Location:
    Hamburg
    #1
    I've been trying to find a way for iTunes to automatically start playing a playlist when you open it. All it does is bring up the song list and you have to manually click play.
    I know it sounds pretty trivial, but I was trying to set it up so that I could schedule my PB to start up at a certain time, and set iCal to open a file instead of an alarm. The file I wanted to open was the playlist. I thought a bit of music would be a nice thing to wake up to ;)
    Anyway, it kind of defeats the purpose if iTuens won't automatically start playing the songs.

    Am I missing something or is there an easier/ different way to do this?

    Thanks for your ideas!
     
  2. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    I think AppleScript is the best way to do this. I wrote the following script which will open iTunes (if necessary) and start playing the first song of the selected playlist. If anything is playing when it is run, it will be stopped so that the first song of the selected playlist can be played.

    To setup the script follow these steps:
    1. Open /Applications/AppleScript/Script Editor
    2. Paste the following code:
    Code:
    property playlistName : "" --Enter name of playlist or leave blank to be prompted on run
    
    tell application "iTunes"
    	--Prompt for a playlist if none is selected
    	if playlistName is "" then
    		set playlistName to text returned of (display dialog "What is the name of the playlist?" default answer "" with icon note)
    	end if
    	
    	--Find the playlist with the chosen name
    	repeat with i from 1 to (count of playlists)
    		set thePlaylist to null
    		if name of playlist i is playlistName then
    			set thePlaylist to playlist i
    			exit repeat
    		end if
    	end repeat
    	
    	--Display an error if the playlist can't be found
    	if thePlaylist is null then
    		display dialog "The chosen playlist does not appear to exist. Relaunch this script to choose another." buttons "OK" default button "OK" with icon caution
    		set playlistName to ""
    	else
    		
    		--Stop anything that might be playing
    		if player state is playing then
    			stop
    		end if
    		
    		--Select the playlist and start playing
    		set view of browser window 1 to thePlaylist
    		play
    	end if
    end tell
    3. If you want to write the name of the playlist to play into the script, put its name into the speech marks on the first line of code. Otherwise, you can choose the playlist in step 5.
    4. Save as application, with all options unchecked.
    5. If you haven't written the playlist name into the script, then open the application and type the name of the playlist. The application will remember the playlist from now on. If you ever want to change the playlist name after that, you'll need to resave the script (to do this, open it in Script Editor, save and close).
    6. Set up the alarm in iCal and choose the script as the file.
     

Share This Page