iTunes - add song then set genre

Hello, this is my first shot at an applescript. I am attempting to create a droplet where I can:

  • drop an mp3 file onto it
  • import that mp3 to iTunes
  • ask me for my choice of which genre I would like the mp3 file to be
  • set that genre

I started this script this morning and have tried multiple different methods to get this to work, I have got the menu that asks for my choice to work, as well as the import of the file, but I cannot get the set genre portion to work. Any help or advice would be greatly appreciate!

Thanks ahead for your help, Merry Christmas/ Happy Holidays!

global choiceGenre
global askGenre
global choiceGenre
global sort_Music
global music_item
global added_track
on open sort_Music -- START
	tell application "iTunes" to activate
	delay 2
	repeat with i from 1 to the count of sort_Music
		set music_item to item i of sort_Music
		set the item_info to info for music_item
		try
			set music_extension to the name extension of this_info
		end try
		try
			set music_filetype to the file type of this_info
		end try
		try
			set music_typeID to the type identifier of this_info
		end try
	end repeat
	try
		makeChoice(music_item)
	end try
	try
		process_item(music_item)
	end try
	try
		tag_item(music_item)
	end try
	try
		set guiMsg to "You chose " & choiceGenre & "."
		display dialog guiMsg
	end try
end open

on makeChoice(music_item)
	set added_track to sortMuisc
	set askGenres to {"Baroque Music", "Country", "Classic Rock", "Alternative Rock", "Rock", "Electronic Pop", "Pop", "Rap", "R&B", "Chill/Ambient", "Dubstep"}
	
	
	set choiceGenre to (choose from list askGenres)
end makeChoice

on process_item(music_item)
	tell application "iTunes"
		add music_item
		delay 2
	end tell
end process_item
on tag_item(music_item)
	tell application "iTunes"
		set genre of music_item to choiceGenre
	end tell
end tag_item


I redesigned it some and have got the script to work for the most part. The problem I am having now is the script will set the genre but will not set the grouping.

If someone could point out what I’m doing wrong and or help me fix this script that would be great. Keep in mind I am just learning and any help will be greatly appreciated!

(*
Application designed to import audio files into iTunes and subsequencly ID3 tag them in the "Genre" and "Grouping" fields specificaly with user choice input, then delete the original file.
*)

--define variables
global genre_choice
global grouping_choice
global genre_list
global grouping_list
global display_choice

--on drop of file which open script/app
on open import_tag
	
	tell application "iTunes" to activate -- activates iTunes
	
	
	repeat with i from 1 to the count of import_tag --repeats till all files dropped done
		set audio_file to item i of import_tag
		try
			set genre_list to {"Baroque Music", "Country", "Classic Rock", "Alternative Rock", "Rock", "Electronic Pop", "Pop", "Rap", "R&B", "Chill/Ambient", "Dubstep"}
			choose from list genre_list with prompt "Choose Genre:"
			set genre_choice to result as text
			
			set grouping_list to {"Fast", "Medium", "Slow"}
			choose from list grouping_list with prompt "Choose grouping:"
			set grouping_choice to result as text
			
			display dialog genre_choice & " & " & grouping_choice
		on error
			display dialog "Cannot set user choices" buttons "Okay"
		end try
		
		try
			tell application "iTunes"
				add audio_file to playlist "import_tag"
				tell playlist "import_tag" to set genre of first track to genre_choice
				tell playlist "import_tag" to set grouping of first track to grouping_choice
			end tell
		on error
			display dialog "Cannot set genre or grouping" buttons "Okay"
		end try
		
		
		
	end repeat
end open

Finally figured it out, any other tips so I can improve upon this script let me know please! Thanks again!

(*
Application designed to import audio files into iTunes and subsequencly ID3 tag them in the "Genre" and "Grouping" fields specificaly with user choice input, then delete the original file.
*)

--define variables
global genre_choice
global grouping_choice
global genre_list
global grouping_list
global display_choice
global import_file
global set_tagging

--on drop of file which open script/app
on open import_tag
	
	repeat with i from 1 to the count of import_tag --repeats till all files dropped done
		set audio_file to item i of import_tag
		try
			set genre_list to {"Baroque Music", "Country", "Classic Rock", "Alternative Rock", "Rock", "Electronic Pop", "Pop", "Rap", "R&B", "Chill/Ambient", "Dubstep"}
			choose from list genre_list with prompt "Choose Genre:"
			set genre_choice to result as text
			
			set grouping_list to {"Fast", "Medium", "Slow"}
			choose from list grouping_list with prompt "Choose tempo:"
			set grouping_choice to result as text
		on error
			display dialog "Cannot set user choices" buttons "Okay"
		end try
		
		tell application "iTunes"
			add audio_file to playlist "import_tag"
			
			set grouping of (track 1 of playlist "import_tag") to grouping_choice
			delay 1
			set genre of (track 1 of playlist "import_tag") to genre_choice
		end tell
		
	end repeat
end open