help needed to improve an itunes script

heres my script i made using different scripts around it works but i want to improve some things, it basically create a playlist to every folder containing an album, now i have to select all folders and drop them on the droplet



on open (the_items)
	set folder_count to 0
	tell application "Finder"
		set the_count to (count the_items)
		repeat with f from 1 to the_count
			
			set this_item to item f of the_items
			
			
			set theName to this_item as string
			set old_delims to AppleScript's text item delimiters
			set AppleScript's text item delimiters to ":"
			set playlist_name to text item -2 of theName
			set AppleScript's text item delimiters to old_delims
			set folder_count to folder_count + 1
			
			tell application "iTunes"
				set new_playlist to make new user playlist
				set name of new_playlist to playlist_name as string
				
				
				add this_item to new_playlist
			end tell
			
		end repeat
	end tell
end open


what i want to improve for example:
-be able to use it from the script menu in itunes
-so it can scan one folder where i keep all my albums (all folders are at the same level)

i have a problem using “list folder” command, the system says it cant get the name of the folders

please help ill post on applescript itunes website

I’m not entirely sure why you’d want to add this to iTunes’ script menu since I wouldn’t expect it to be something you’re likely to want to run frequently, but if you want to, all you need to do is save your script in ~/Library/iTunes/Scripts/ and it’ll appear.

With respect to adding multiple playlists, one for each folder, something like this should work (untested):

set topFolder to choose folder with prompt "Choose the top level folder"

tell application "Finder"
	set albumList to every folder of topFolder
	repeat with anAlbum in albumList
		set tracks to every file of anAlbum
		tell application "iTunes"
			set new_playlist to make new user playlist with properties {name:name of anAlbum as string}
			add tracks to new_playlist
		end tell
	end repeat
end tell

This will create a new playlist for each folder inside the folder you select at the beginning, and it will add each file inside that folder to the new playlist.

thank you for answer
it does create a new playlist with correct name corresponding to each folder
BUT playlist are empty

i found an app (which is a droplet script ) that does the job but i still think its more elegant to get the job done from the script menu

(strangely
add album_tracks to new_playlist
is different from
add tracks to new_playlist
in script editor in the later case “tracks” is in blue
but there is no difference in the result

the link to the app found
http://hagenstrom.de/software/playlisbot1.1.0b3-osx.sit

Oops, my bad. ‘tracks’ is a reserved word in iTunes. I should have used a better variable name. Try ‘theTracks’ instead.

Also, you might want to add some error trapping logic to make sure that, for example, the playlist doesn’t already exist.

mmm.
as i said in the last post changing “tracks” to “the_tracks” generate another error.
i dont know how to paste it here

You did change both references to ‘tracks’, right?

set topFolder to choose folder with prompt "Choose the top level folder" 
 
tell application "Finder" 
   set albumList to every folder of topFolder 
   repeat with anAlbum in albumList 
      set the_Tracks to every file of anAlbum 
      tell application "iTunes" 
         set new_playlist to make new user playlist with properties {name:name of anAlbum as string} 
         add the_Tracks to new_playlist 
      end tell 
   end repeat 
end tell

yes. but stil doesnt work