All pastes #918456 Raw Edit

Untitled

public text v1 · immutable
#918456 ·published 2008-02-26 03:07 UTC
rendered paste body
using terms from application "Colloquy"
	
	on process user command c with arguments for view
		
		if c is "itunes" then
			
			set itunes_active to false
			
			tell application "Finder"
				if (get name of every process) contains "iTunes" then
					set itunes_active to true
				end if
			end tell
			
			if itunes_active then
				set itunes_message to do_itunes()
				tell view to send message itunes_message with action tense
			end if
			return true
			
		end if
		return false
		
	end process user command
	
end using terms from

on do_itunes()
	
	set got_track to false
	
	tell application "iTunes"
		if player state is playing then
			set theTrack to name of the current track
			set theArtist to artist of the current track
			set theAlbum to album of the current track
			set theBitrate to bit rate of the current track
			set theRating to rating of the current track
			set got_track to true
		end if
	end tell
	
	-- we have the track info
	
	if got_track then
		
		-- create the contents of the message
		
		if theArtist is not "" then
			set artistinfo to " by " & theArtist
		else
			set artistinfo to ""
		end if
		if theAlbum is not "" then
			set Albuminfo to " on " & theAlbum
		else
			set Albuminfo to ""
		end if
		if theRating is "*****" then
			set isFavorite to " This track is marked as a favorite."
		else
			set isFavorite to ""
		end if
		set theContents to "is listening to " & theTrack & artistinfo & Albuminfo & " at " & theBitrate & " Kbps." & isFavorite
		
		return theContents
		
	end if -- end of we have track info
end do_itunes