I had to make a few changes to get it to work, so I'll go through the code bit by bit.
Code:
property playlistused : "test"
tell application "Finder"
--set mainFolder to folder "Test" of folder "MP3" of disk "no name" as string
set mainFolder to folder "test folder" of folder "iTunes Scripts" of desktop as string
set mainFolder to (make new folder at folder mainFolder with properties {name:"testfile"})
end tell
Here I set
mainFolder to the new folder that you created. If I understand you correctly, you want to add the music files to the
testfile folder, not
test folder, but if this isn't the case you can revert this code back to what you had before.
Code:
tell application "iTunes"
--set oldfi to fixed indexing - means tracks go from 1 to x
set oldfi to fixed indexing
set fixed indexing to true
copy (count playlist playlistused's tracks) to ix
In the last line, I changed
(count playlistused's tracks) to
(count playlist playlistused's tracks). Without the word
playlist, it doesn't know that it's a playlist, so it incorrectly sets ix to 0 (which is what caused your original script to do nothing).
Code:
repeat with i from 1 to ix
copy (get name of track i of user playlist playlistused) to trackName
copy (get album of track i of user playlist playlistused) to trackAlbum
copy (get artist of track i of user playlist playlistused) to trackArtist
copy track i of playlist playlistused to thisTrack
copy (get thisTrack's location) to track_location_in_finder
Again, I added the word
playlist before
playlistused on the second to last line.
Code:
tell application "Finder"
copy (get name of (get info for (track_location_in_finder as alias))) as string to fixed_filename
copy (get container of track_location_in_finder) as string to source_folder
end tell
copy (source_folder & fixed_filename) as string to location_in_finder_info_name
Here I changed
location_in_finder (which wasn't defined) to
track_location_in_finder several times.
Code:
--my set_item_name(location_in_finder_info_name, itunes_track_name)
tell application "Finder"
set aFile to duplicate (location_in_finder_info_name as alias) to mainFolder
set name of aFile to trackName & ".mp3" as string
end tell
I commented out the first line since I don't have your code for
set_item_name. I also changed the
duplicate line, which gave an error with your code. Finally, I added a line to rename the file to its iTunes track name (rather than its filename), which is what I suspect the purpose of
set_item_name might have been.
The rest of the code is unchanged:
Code:
end repeat
set fixed indexing to oldfi
end tell
Here's the code in one segment:
Code:
property playlistused : "test"
tell application "Finder"
--set mainFolder to folder "Test" of folder "MP3" of disk "no name" as string
set mainFolder to folder "test folder" of folder "iTunes Scripts" of desktop as string
set mainFolder to (make new folder at folder mainFolder with properties {name:"testfile"})
end tell
tell application "iTunes"
--set oldfi to fixed indexing - means tracks go from 1 to x
set oldfi to fixed indexing
set fixed indexing to true
copy (count playlist playlistused's tracks) to ix
repeat with i from 1 to ix
copy (get name of track i of user playlist playlistused) to trackName
copy (get album of track i of user playlist playlistused) to trackAlbum
copy (get artist of track i of user playlist playlistused) to trackArtist
copy track i of playlist playlistused to thisTrack
copy (get thisTrack's location) to track_location_in_finder
tell application "Finder"
copy (get name of (get info for (track_location_in_finder as alias))) as string to fixed_filename
copy (get container of track_location_in_finder) as string to source_folder
end tell
copy (source_folder & fixed_filename) as string to location_in_finder_info_name
--my set_item_name(location_in_finder_info_name, itunes_track_name)
tell application "Finder"
set aFile to duplicate (location_in_finder_info_name as alias) to mainFolder
set name of aFile to trackName & ".mp3" as string
end tell
end repeat
set fixed indexing to oldfi
end tell