Using Applescript to Populate Nicecast’s NowPlaying.txt File

[Rogue Amoeba][rogue] 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][nice]. I sometimes use Nicecast to stream audio to friends and relatives, and it’s very good software.

[rogue]: http://www.rogueamoeba.com/ “Rogue Amoeba”
[ice]: http://www.icecast.org/ “Icecast”
[nice]: http://www.rogueamoeba.com/nicecast/ “Nicecast”

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][donation].

[donation]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=D7BP64QCQ9SPN “Donate via PayPal”


Comments

One response to “Using Applescript to Populate Nicecast’s NowPlaying.txt File”

  1. “Library/Application Support/Nicecast/NowPlaying.txt” should be “/Library/Application Support/Nicecast/NowPlaying.txt” for script to populate file

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.