Create a radio station with announcements via Nicecast

Apr 07, '08 07:30:00AM

Contributed by: SeƱor Epiphyte

I love my music library, iTunes, and I love news. I have used this hint in the past to automate insertion of CNN and NPR news podcasts into the current Party Shuffle, where I can enjoy music with CNN at the top and NPR at the bottom of the hour.

When I discovered Nicecast last year, I began enjoying my own radio station at work with news and New Music Tuesdays continuously. While debugging a modification to the original AppleScript which would also use the AppleScript say command to announce the time, I accidentally discovered that the time would announce via Nicecast, given activation of iTunes. Read on to see the series of scripts I use...

To announce current song or play Party Shuffle:

-- Play Party Shuffle to keep it going.
tell application "System Events"
  if (name of processes) contains "iTunes" then
    tell application "iTunes"
      -- Don't insert this if we're not listening to the Party Shuffle
      if (player state is playing) then
        set currenttrack to the name of current track
        set currentartist to the artist of current track
        -- set currentalbum to the album of current track
    
        say "You're listening to"
        say (currenttrack)
        say "by"
        say (currentartist)
    
      else
        say time string of (current date)
        say ("Me Likey Music, Let's Go!")
        play playlist "Party Shuffle"
    
      end if
    end tell
  end if
end tell
To speak the time:
-- Tell the time if we're listening to Party Shuffle in iTunes
tell application "System Events"
  if (name of processes) contains "iTunes" then
    tell application "iTunes"
      if (player state is playing and name of current playlist is "Party Shuffle") then
        say "The time is currently"
        say time string of (current date)
      end if
    end tell
  end if
end tell
Radio station ID:
-- Say Something Witty if we're listening to Party Shuffle in iTunes
tell application "System Events"
  if (name of processes) contains "iTunes" then
    tell application "iTunes"
      if (player state is playing and name of current playlist is "Party Shuffle") then
        say "Listening to My Music Station dot Calm!"
      end if
    end tell
  end if
end tell
Play New Music Tuesday (NMT) uses this hint:
-- Insert the newest iTunes NMT update into the party shuffle, if we're listening to it.
tell application "System Events"
  if (name of processes) contains "iTunes" then
    tell application "iTunes"
      -- Get the newest iTunes news update
      set podcastPlaylist to playlist "Podcasts"
      tell podcastPlaylist
        set iTunesUpdates to (every track whose artist is "Apple Inc." and date added is greater than ((current date) - 961 * minutes))
        -- Only add the very latest update.
        set iTunesUpdate to (a reference to item 1 of iTunesUpdates)
      end tell
      -- Don't insert this if we're not listening to the Party Shuffle
      if (player state is playing and name of current playlist is "Party Shuffle") then
        my ps_play_next_ref(iTunesUpdate)
        say ("Eye Tunes New Music Tuesday Broadcast, up next.")
      end if
    end tell
  end if
end tell
-- Append Ref to Party Shuffle after current song
  on ps_play_next_ref(theTrackReference)
    tell application "iTunes"
      set thePlaylist to playlist "Party Shuffle"
      try
        play thePlaylist
        set isPlaying to container of current track is thePlaylist
        if (isPlaying) then set startIndex to index of current track
      on error
          set isPlaying to false
          set startIndex to 0
      end try
    tell thePlaylist
      set oldTracks to a reference to (every track whose index > startIndex and index is less than or equal to (count tracks))
      duplicate theTrackReference to thePlaylist
      duplicate oldTracks
      delete oldTracks
    end tell
  end tell
end ps_play_next_ref
[robg adds: I haven't tested these scripts.]

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080329205627989