Change 'name" in iTunes

Hi,¨I am an applescript newbie.¨I have some songs, videos which have “name” in iTunes different from the file name of the song. I have no idea where it gets the name from. I checked everything in “Get Info” of the song but I could not find the file name. So, I decided to write a script which replaces the “name” in iTunes with the file name of the song. I am stuck at the last step of the script which i have commented with () where i want to assign the name of the song retrieved from its location to the name in iTunes. Thanks.¨

property myPlayList : "xyz"
tell application "iTunes"
	repeat with t from 1 to (index of last track of playlist myPlayList)
		try
			--with timeout of 30 seconds
			set aTrack to (track t of playlist myPlayList)
			try
				set trackName to (get name of aTrack)
				set trackLoc to (get location of aTrack)
				set trackLoc to trackLoc as string
				set AppleScript's text item delimiters to ":"
				--to get the name instead of location
				set newlist to the text items of trackLoc
				set newName to the last item of newlist
				set AppleScript's text item delimiters to "."
				--to remove the extension from the name
				set newName to the text items of newName
				set finalName to the first item of newName
				(*tell contents of aTrack
		set name to finalName
	end tell*)
			end try
			--end timeout
		end try
	end repeat
end tell

Hi,

actually you script should work. While developing scripts it’s always recommended to comment out all try blocks.
When an error occurs, you will be informed.

This is an easier version, it creates 2 lists, one with the location aliases and one with the tracks themselves


property myPlayList : "xyz"

tell application "iTunes" to tell tracks of playlist myPlayList to set {trackList, locationList} to {it, its location}
repeat with i from 1 to count trackList
	set {name:Nm, name extension:Ex} to info for item i of locationList
	if Ex is not missing value then set Nm to text 1 thru ((offset of Ex in Nm) - 2) of Nm
	tell application "iTunes" to set name of item i of trackList to Nm
end repeat

Thanks for the reply. You are correct (as always). My script does work. Actually, when I work on a script, i work only for one item because i know i can use the “repeat” later. So i was not using the script that i posted in the forum.
I was using

set oneTrack to track 11 of playlist myPlayList

My playlist was sorted based on name. All the songs in the playlist had the same name. So when i used my script for one song it got renamed and shifted to the bottom of the list(because sorting was based on “name”) and i did not scroll down to see it because i was assuming it to be at number 11.
Vow!! I wrote a script which works and I could not find out it works!

I will take care, next time.