This script has a greatly dangerous flaw:
tell application "iTunes"
set i to 1
set total to the number of current playlist's tracks
repeat with tr in current playlist's tracks
set tr's track number to i
set tr's track count to total
set i to (i + 1)
end repeat
end tell
You have to be playing something in that playlist for this to actually work. Otherwise I guess it starts numbering the tracks in your entire library (if the current song was selected from the "Library" view).
I actually wanted:
tell application "iTunes"
repeat with bw in browser windows
set pl to bw's view
set i to 1
set total to the number of pl's tracks
repeat with tr in pl's tracks
set tr's track number to i
set tr's track count to total
set i to (i + 1)
end repeat
end repeat
end tell