Using Applescript to Populate Nicecast’s NowPlaying.txt File

Rogue Amoeba has been a big name in consumer audio software for Mac OS X since their inception. One of their biggest apps is an application for streaming audio to the web from your Mac called Nicecast. I sometimes use Nicecast to stream audio to friends and relatives, and it’s very good software.

There’s one thing that annoys me, though: Nicecast doesn’t automatically update the stream you send with the artist and track title, so your listeners don’t know what they’re hearing unless they’ve either heard it before or ask you. Luckily for us, this is OS X, and that means we have access to Applescript.

Cutting to the chase: copy and paste the code below into Applescript Editor (Located in the ApplicationsUtilities folder on your hard drive) and save it somewhere. Line-wraps are marked ¬, which should be removed from your copy/pasted code.

property sleepTime : 10

repeat
    tell application "iTunes"
        try
            if not (exists current track) then return
            set this_artist to (get artist of current track)
            set this_track to (get name of current track)
        end try
    end tell

    tell application "Finder"
        try
            set current_user to do shell script "whoami"
            set the_file to "/Users/" & current_user & ¬ 
            "Library/Application Support/Nicecast/NowPlaying.txt"

            set eof of the_file to 0
            write ("Artist: " & this_artist & return & "Title: " & ¬ 
            this_track) to the_file

        end try
    end tell
    do shell script "/bin/sleep " & sleepTime
end repeat

The script updates your NowPlaying.txt file every 10 seconds (you can change that setting by modifying the sleepTime property), until you tell it to stop by hitting the “Stop” button in Applescript Editor.

If you found this script useful, a donation would make me feel pretty good about this use of my time.