new Version with Genre List
set myfile to choose file with prompt "Select Audio File" of type {"mp3", "m4a"}
set inputFile to quoted form of POSIX path of myfile
set myInfo to (do shell script "mdls " & inputFile & " |\nsed -En ' # Massage the ˜mdls' result into a text representation of an Applecript record.\n# For convenience, shorten the property labels by replacing ˜kMDItem' with ˜_'.\ns/^kMDItem/_/\n# If a line begins with ˜_' and does not end with ˜(':\n/^_/ {\n/\\($/ !{\n# Replace everything between the label and the value with ˜:' and remove any existing quotes from around the value.\ns/ += \"?/:/\ns/\"$//\n# Add another layer of escape to any remaining quotes in the value.\ns/\"/\\\\\"/g\n# Put doubly-escaped quotes round any ˜_Title' or ˜_Album' value.\n/^_Title:|^_Album:/ s/:(.*)/:\\\\\"\\1\\\\\"/\n# Put ordinary (singly-escaped) quotes round what ever the value is now.\ns/:(.*)/:\"\\1\"/\n}\n}\n# If a line ends with ˜(' or is ˜)' or is an idented line occurring between such lines:\n/\\($/,/^\\)/ {\n# If it's an indented line, strip the leading spaces and any wrapping quotes or trailing commas, add another layer of escape to any remaining quotes, and append a slash.\n/^ / {\n s/^ +\"?|\"?,?$//g\n s/\"/\\\\\"/g\n s/$/\\//\n}\n# If it's the ˜(' line (a label line, beginning with ˜_'), substitute a colon and a quote for everything after the label.\ns/^(_[^ ]+).*/\\1:\"/\n# If it's the ˜)' line, substitute a quote for the ˜)'.\ns/^\\)/\"/\n}\n# Append whatever's been done to this line above to the hold space.\nH\n# When the last line's been done:\n$ {\n# Retrieve all the edited text from the hold space and put braces round it, ditching an incidental linefeed at the beginning.\ng\ns/^\\n(.*)/{\\1}/\n# Combine the groups of lines formerly between ˜(' and ˜)' lines into single lines.\ns/(\\n_[^:]+:\"|\\/)\\n/\\1/g\ns/\\/\"/\"/g\n# Replace the linefeeds in the rest of text with ˜, '.\ns/\\n/, /g\n# Return the final result to be compiled into an AppleScript record.\np\n}'")
set the clipboard to myInfo
-- Convert the returned "record" text to an actual record, with "" values where the labels which interest us don't exist.
set myInfo to (run script myInfo) & {_Album:"", _AudioBitRate:"", _AudioEncodingApplication:"", _AudioSampleRate:"", _Authors:"", _Kind:"", _MusicalGenre:"", _RecordingYear:"", _Title:"", _Composer:"", _Comment:"", _AudioTrackNumber:""}
set {_Album:songalbum, _AudioBitRate:songbitrate, _AudioEncodingApplication:encoder, _AudioSampleRate:samplerate, _Authors:songartist, _Kind:encoding, _MusicalGenre:songgenre, _RecordingYear:songyear, _Title:songname, _PhysicalSize:filesize, _Composer:songcomposer, _AudioTrackNumber:songnumber, _Comment:songcomment} to myInfo
if quote is in songname then
set AppleScript's text item delimiters to quote
set songname to songname's text items
set songname to item 2 of songname
end if
if quote is in songcomment then
set AppleScript's text item delimiters to quote
set songcomment to songcomment's text items
set songcomment to item 2 of songcomment
end if
if quote is in songalbum then
set AppleScript's text item delimiters to quote
set songalbum to songalbum's text items
set songalbum to item 2 of songalbum
end if
if quote is in songcomposer then
set AppleScript's text item delimiters to quote
set songcomposer to songcomposer's text items
set songcomposer to item 2 of songcomposer
end if
if quote is in songgenre then
set AppleScript's text item delimiters to quote
set songgenre to songgenre's text items
set songgenre to item 2 of songgenre
end if
--genre numbers to text
if songgenre = "0" then
set songgenre to "Blues"
else if songgenre = "1" then
set songgenre to "Classic Rock"
else if songgenre = "2" then
set songgenre to "Country"
else if songgenre = "3" then
set songgenre to "Dance"
else if songgenre = "4" then
set songgenre to "Disco"
else if songgenre = "5" then
set songgenre to "Funk"
else if songgenre = "6" then
set songgenre to "Grunge"
else if songgenre = "7" then
set songgenre to "Hip-Hop"
else if songgenre = "8" then
set songgenre to "Jazz"
else if songgenre = "9" then
set songgenre to "Metal"
else if songgenre = "10" then
set songgenre to "New Age"
else if songgenre = "11" then
set songgenre to "Oldies"
else if songgenre = "12" then
set songgenre to "Other"
else if songgenre = "13" then
set songgenre to "Pop"
else if songgenre = "14" then
set songgenre to "Rhythm and Blues"
else if songgenre = "15" then
set songgenre to "Rap"
else if songgenre = "16" then
set songgenre to "Reggae"
else if songgenre = "17" then
set songgenre to "Rock"
else if songgenre = "18" then
set songgenre to "Techno"
else if songgenre = "19" then
set songgenre to "Industrial"
else if songgenre = "20" then
set songgenre to "Alternative"
else if songgenre = "21" then
set songgenre to "Ska"
else if songgenre = "22" then
set songgenre to "Death Metal"
else if songgenre = "23" then
set songgenre to "Pranks"
else if songgenre = "24" then
set songgenre to "Soundtrack"
else if songgenre = "25" then
set songgenre to "Euro-Techno"
else if songgenre = "26" then
set songgenre to "Ambient"
else if songgenre = "27" then
set songgenre to "Trip-Hop"
else if songgenre = "28" then
set songgenre to "Vocal"
else if songgenre = "29" then
set songgenre to "Jazz & Funk"
else if songgenre = "30" then
set songgenre to "Fusion"
else if songgenre = "31" then
set songgenre to "Trance"
else if songgenre = "32" then
set songgenre to "Classical"
else if songgenre = "33" then
set songgenre to "Instrumental"
else if songgenre = "34" then
set songgenre to "Acid"
else if songgenre = "35" then
set songgenre to "House"
else if songgenre = "36" then
set songgenre to "Game"
else if songgenre = "37" then
set songgenre to "Sound Clip"
else if songgenre = "38" then
set songgenre to "Gospel"
else if songgenre = "39" then
set songgenre to "Noise"
else if songgenre = "40" then
set songgenre to "Alternative Rock"
else if songgenre = "41" then
set songgenre to "Bass"
else if songgenre = "42" then
set songgenre to "Soul"
else if songgenre = "43" then
set songgenre to "Punk"
else if songgenre = "44" then
set songgenre to "Space"
else if songgenre = "45" then
set songgenre to "Meditative"
else if songgenre = "46" then
set songgenre to "Instrumental Pop"
else if songgenre = "47" then
set songgenre to "Instrumental Rock"
else if songgenre = "48" then
set songgenre to "Ethnic"
else if songgenre = "49" then
set songgenre to "Gothic"
else if songgenre = "50" then
set songgenre to "Darkwave"
else if songgenre = "51" then
set songgenre to "Techno-Industrial"
else if songgenre = "52" then
set songgenre to "Electronic"
else if songgenre = "53" then
set songgenre to "Pop-Folk"
else if songgenre = "54" then
set songgenre to "Eurodance"
else if songgenre = "55" then
set songgenre to "Dream"
else if songgenre = "56" then
set songgenre to "Southern Rock"
else if songgenre = "57" then
set songgenre to "Comedy"
else if songgenre = "58" then
set songgenre to "Cult"
else if songgenre = "59" then
set songgenre to "Gangsta"
else if songgenre = "60" then
set songgenre to "Christian Rap"
else if songgenre = "61" then
set songgenre to "Pop/Funk"
else if songgenre = "62" then
set songgenre to "Jungle"
else if songgenre = "63" then
set songgenre to "Native US"
else if songgenre = "64" then
set songgenre to "Cabaret"
else if songgenre = "65" then
set songgenre to "New Wave"
else if songgenre = "66" then
set songgenre to "Psychedelic"
else if songgenre = "67" then
set songgenre to "Rave"
else if songgenre = "68" then
set songgenre to "Showtunes"
else if songgenre = "69" then
set songgenre to "Trailer"
else if songgenre = "70" then
set songgenre to "Lo-Fi"
else if songgenre = "71" then
set songgenre to "Tribal"
else if songgenre = "72" then
set songgenre to "Acid Punk"
else if songgenre = "73" then
set songgenre to "Acid Jazz"
else if songgenre = "74" then
set songgenre to "Polka"
else if songgenre = "75" then
set songgenre to "Retro"
else if songgenre = "76" then
set songgenre to "Musical"
else if songgenre = "77" then
set songgenre to "Rock & Roll"
else if songgenre = "78" then
set songgenre to "Hard Rock"
else if songgenre = "79" then
set songgenre to ""
end if
set mypic to (choose file of type {"png", "jpg"} with prompt "Select Picture for Artwork")
set mypic to mypic as text
set imageData to (read file (mypic) as data)
tell application "iTunes"
set thetrack to add myfile
set artist of thetrack to the text returned of (display dialog "Artist:" default answer songartist)
set name of thetrack to the text returned of (display dialog "Song Name:" default answer songname)
set year of thetrack to the text returned of (display dialog "Year:" default answer songyear)
set comment of thetrack to the text returned of (display dialog "Comment:" default answer songcomment)
set album of thetrack to the text returned of (display dialog "Album:" default answer songalbum)
set composer of thetrack to the text returned of (display dialog "Composer:" default answer songcomposer)
set genre of thetrack to (choose from list {songgenre, "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "Rhythm and Blues", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz & Funk", "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "Alternative Rock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta", "Christian Rap", "Pop/Funk", "Jungle", "Native US", "Cabaret", "New Wave", "Psychedelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock"} default items songgenre)
set data of artwork 1 of thetrack to imageData
--set TRKN of thetrack to the text returned of (display dialog "Track Nr:" default answer songnumber)
end tell