iTunes new track

Hi,

I’m having another problem with my project … I need to know when a new track has started in iTunes and then check if track’s name equals to the one already written into a file. Well, I got it working quite nicely, but it made the game lag. I think you need to know about the project itself, because it might be confusing at the moment. The project is about this: player launches my application, then minimizes it, launches quake 3 and when he/she presses a button, it will tell the current song. The current song data is saved in a .cfg file, which will be executed when he/she presses a button. Everything works well, except it lags like hell. It skips. I tried very many different ways of doing it. The most lag-free solution was this:

set trackChecked to false
set writeIntoFile to false
if trackChecked is not equal to true then
	set trackComparison to do shell script "cat " & outputFileLocation
	if trackComparison is not equal to finalSyntax then
		set writeIntoFile to true
	else
		set trackChecked to false
		set writeIntoFile to false
	end if
end if
	
if writeIntoFile is equal to true then
	do shell script "cat /dev/null > " & outputFileLocation
	do shell script "echo " & quoted form of finalSyntax & " > " & outputFileLocation
	set writeIntoFile to false
	set trackChecked to true
end if

I guess the do shell script is the problem, to be more specific, I think this:

set trackComparison to do shell script "cat " & outputFileLocation

is a problem, since it keeps comparing the contents of a .cfg file to a string over and over again, but I’m not sure. I didn’t find any other way to compare the files content to a string.

I hope you can help me out!

Thanks,
dr4cula

Found a solution:

set lastPlayedTrack to contents of default entry "lastTrack" of user defaults
	
if lastPlayedTrack is not equal to current_title then
	set searchStrings to {"<artist>", "<title>", "<album>", "<length>"}
	set replacementStrings to {current_artist, current_title, current_album, current_track_length}
	set userSyntax to contents of text field "formatField" of window "main"
	set finalSyntax to format_type & " " & syntaxFormat(searchStrings, replacementStrings, userSyntax)
	do shell script "cat /dev/null > " & outputFileLocation
	do shell script "echo " & quoted form of finalSyntax & " > " & outputFileLocation
	set contents of default entry "lastTrack" of user defaults to current_title
end if

But I have one question. The data is being saved into the .plist file, but when I check it, it’s not there. The last value is there, even though it’s value should have been changed already. The correct value is there after I re-compile it. But then again, the script doesn’t run itself over and over again and works as expected. Can anyone tell me, why I can’t see the changed value right away?

Thanks,
dr4cula