Log what you listen in iTunes to log

Is it possible to log what songs you listen in iTunes to log file?

Try this save it as a stay open application

global last_playlName
on run
	set last_playlName to ""
end run
on idle
	tell application "iTunes"
		set thepath to path to documents folder from user domain as string
		set thepath to POSIX path of thepath
		set this_playlName to the name of current track
		set albumName to the album of current track
		set ArtistName to the artist of current track
		
		
		
		if last_playlName is equal to this_playlName then
			return 30
		else if last_playlName is not equal to this_playlName then
			
			set thesWritlog to do shell script "echo " & "SONG _ " & quoted form of this_playlName & " \\)  \\:  " & "ALBUM _  " & albumName & " \\)  \\:  " & " ARTIST _ " & ArtistName & "  \\) >> " & thepath & "played.log"
			set last_playlName to this_playlName
		end if
		
	end tell
	return 30
end idle



Just a small update to cope with illegal characters in in the text.

global last_playlName
on run
	set last_playlName to ""
end run
on idle
	tell application "iTunes"
		set thepath to path to documents folder from user domain as string
		set thepath to POSIX path of thepath
		set this_playlName to the name of current track
		set albumName to the album of current track
		set ArtistName to the artist of current track
		
		
		
		if last_playlName is equal to this_playlName then
			return 30
		else if last_playlName is not equal to this_playlName then
			
			set thesWritlog to do shell script "echo " & "SONG _ " & quoted form of this_playlName & " \\)  \\:  " & "ALBUM _  " & quoted form of albumName & " \\)  \\:  " & " ARTIST _ " & quoted form of ArtistName & "  \\) >> " & thepath & "played.log"
			set last_playlName to this_playlName
		end if
		
	end tell
	return 30
end idle