Getting ID3 tags from an MP3 file without using iTunes?

Is there a simple way I can pull the ID3 tags (Artist, Song Name, Album, etc.) from an MP3 file in the Finder with Applescript without having to send the file to iTunes? I noticed that can look at the tags from the Finder within the Get Info window or through a QuickLook plugin, but is the Finder doing that with something other than its system events?

I don’t mind piping the files through a shell script command, but I would like to know how to do it without having to wake the iTunes beast.

Model: iMac 27-inch
Browser: Safari 534.57.2
Operating System: Mac OS X (10.7)

You can download ExifTool from here :
http://www.sno.phy.queensu.ca/~phil/exiftool/

I wrote the code below for a Service created in Automator to display metadata of photos, but it should work for mp3s too.

tell application "Finder"
	
	set thePath to (path to documents folder as text) & "exifdata"
	if not (exists thePath) then
		do shell script "mkdir -p " & POSIX path of thePath & ""
	end if
	
	repeat with i from 1 to count of (selection as list)
		set theLocation to POSIX path of (item i of (selection as list) as alias)
		set theItem to item i of (selection as list)
		set theName to (name of theItem as string)
		set theCount to (count of theName) - ((count of (name extension of theItem as string)) + 1)
		set theName to text 1 thru theCount in theName
		set destLocation to "'" & POSIX path of thePath & "/" & theName & ".txt'"
		do shell script "exiftool -a '" & theLocation & "' >" & destLocation
		do shell script "open " & destLocation & ""
	end repeat
end tell

see http://macscripter.net/viewtopic.php?pid=154215

for mp3 or m4a TAG


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)
set the clipboard to myInfo as text

-- fileextension
set fileextension to myfile as text
set text item delimiters of AppleScript to ":"
set fileextension to text items of fileextension
set fileextension to last item of fileextension
set text item delimiters of AppleScript to "."
set fileextension to text items of fileextension
set fileextension to last item of fileextension

-- songname
set findtext to "kMDItemTitle"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set songname to item 2 of someText
	
	set text item delimiters of AppleScript to "="
	set songname to text items of songname
	set songname to item 2 of songname
	
	set text item delimiters of AppleScript to "kMDItemTotalBitRate"
	set songname to text items of songname
	set songname to item 1 of songname
	
	set text item delimiters of AppleScript to return
	set songname to text items of songname
	set songname to item 1 of songname
else
	set songname to ""
end if

-- artist
set findtext to "kMDItemAuthors"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set songartist to item 2 of someText
	
	set text item delimiters of AppleScript to "= (" & return
	set songartist to text items of songartist
	set songartist to item 2 of songartist
	
	set text item delimiters of AppleScript to "    "
	set songartist to text items of songartist
	set songartist to item 2 of songartist
	
	set text item delimiters of AppleScript to "kMDItemContentCreationDate"
	set songartist to text items of songartist
	set songartist to item 1 of songartist
	
	set text item delimiters of AppleScript to return
	set songartist to text items of songartist
	set songartist to item 1 of songartist
else
	set songartist to ""
end if

-- album
set findtext to "kMDItemAlbum"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set songalbum to item 2 of someText
	
	set text item delimiters of AppleScript to "="
	set songalbum to text items of songalbum
	set songalbum to item 2 of songalbum
	
	set text item delimiters of AppleScript to "kMDItemAlternateNames"
	set songalbum to text items of songalbum
	set songalbum to item 1 of songalbum
	
	set text item delimiters of AppleScript to return
	set songalbum to text items of songalbum
	set songalbum to item 1 of songalbum
else
	set songalbum to ""
end if

-- year
set findtext to "kMDItemRecordingYear"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set songyear to item 2 of someText
	
	set text item delimiters of AppleScript to "="
	set songyear to text items of songyear
	set songyear to item 2 of songyear
	
	set text item delimiters of AppleScript to "kMDItemTitle"
	set songyear to text items of songyear
	set songyear to item 1 of songyear
	
	set text item delimiters of AppleScript to return
	set songyear to text items of songyear
	set songyear to item 1 of songyear
else
	set songyear to ""
end if

-- genre
set findtext to "kMDItemMusicalGenre"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set songgenre to item 2 of someText
	
	set text item delimiters of AppleScript to "="
	set songgenre to text items of songgenre
	set songgenre to item 2 of songgenre
	
	set text item delimiters of AppleScript to "kMDItemPhysicalSize"
	set songgenre to text items of songgenre
	set songgenre to item 1 of songgenre
	
	set text item delimiters of AppleScript to return
	set songgenre to text items of songgenre
	set songgenre to item 1 of songgenre
else
	set songgenre to ""
end if

-- songbitrate
set findtext to "kMDItemAudioBitRate"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set songbitrate to item 2 of someText
	
	set text item delimiters of AppleScript to "="
	set songbitrate to text items of songbitrate
	set songbitrate to item 2 of songbitrate
	
	set text item delimiters of AppleScript to "kMDItemAudioChannelCount"
	set songbitrate to text items of songbitrate
	set songbitrate to item 1 of songbitrate
	
	set songbitratevalue to songbitrate as number
	set songbitratevalue to (songbitrate / 1000)
	set songbitrate to songbitratevalue as text
else
	set songbitrate to ""
end if

-- samplerate
set findtext to "kMDItemAudioSampleRate"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set samplerate to item 2 of someText
	
	if "kMDItemContentCreationDate" is in someText then
		set text item delimiters of AppleScript to "="
		set samplerate to text items of samplerate
		set samplerate to item 2 of samplerate
		
		set text item delimiters of AppleScript to "kMDItemContentCreationDate"
		set samplerate to text items of samplerate
		set samplerate to item 1 of samplerate
	else
		set text item delimiters of AppleScript to "kMDItemAudioTrackNumber"
		set samplerate to text items of samplerate
		set samplerate to item 1 of samplerate
		
		set text item delimiters of AppleScript to "="
		set samplerate to text items of samplerate
		set samplerate to item 2 of samplerate
		
		if "kMDItemAudioTrackNumber" is in someText then
			set text item delimiters of AppleScript to "kMDItemAudioTrackNumber"
			set samplerate to text items of samplerate
			set samplerate to item 2 of samplerate
		else
			set text item delimiters of AppleScript to "kMDItemAuthors"
			set samplerate to text items of samplerate
			set samplerate to item 1 of samplerate
		end if
	end if
	
	set sampleratevalue to samplerate --as number
	set sampleratevalue to (sampleratevalue / 1000)
	set samplerate to sampleratevalue as text
else
	set samplerate to ""
end if

-- encoder
set findtext to "kMDItemAudioEncodingApplication"
set replacetext to "" --Text to replace with
set someText to myInfo --Text to be searched

if findtext is in someText then
	set text item delimiters of AppleScript to findtext
	set someText to text items of someText
	set encoder to item 2 of someText
	
	set text item delimiters of AppleScript to "="
	set encoder to text items of encoder
	set encoder to item 2 of encoder
	
	set text item delimiters of AppleScript to "kMDItemAudioSampleRate"
	set encoder to text items of encoder
	set encoder to item 1 of encoder
else
	set encoder to ""
end if

display dialog "Song Name: " & songname & return & return & "Artist: " & songartist ¬
	& return & return & "Album: " & songalbum & return & return & "Year: " & songyear ¬
	& return & return & "Genre: " & songgenre & return & return & "Bitrate: " & songbitrate & ¬
	" kb/s" & return & return & "Samplerate: " & samplerate & ¬
	" kHz" & return & return & "Encoder: " & encoder

Hi axel99092.

Unfortunately your script doesn’t work with some of my mp3s. (I don’t have any m4as to try.) It errors trying to do maths on bit-rate or sample-rate values which still have the following lines attached to them. I’m not sure if it’s because of an error in the script or because of an assumption that one particular label will always follow another.

You may only need to look out for the next instance of “kMDItem” after the found label rather than an entire label. I haven’t tested it thoroughly, but this version of your script is based on the idea:


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)
set the clipboard to myInfo as text

-- fileextension
set fileextension to myfile as text
set text item delimiters of AppleScript to ":"
set fileextension to text items of fileextension
set fileextension to last item of fileextension
set text item delimiters of AppleScript to "."
set fileextension to text items of fileextension
set fileextension to last item of fileextension

set theParticulars to {"kMDItemTitle", "kMDItemAuthors", "kMDItemAlbum", "kMDItemRecordingYear", "kMDItemMusicalGenre", "kMDItemAudioBitRate", "kMDItemAudioSampleRate", "kMDItemAudioEncodingApplication"}

-- Replace each label in theParticulars with the corresponding returned value (or "" if none).
set astid to AppleScript's text item delimiters
repeat with i from 1 to (count theParticulars)
	set findText to item i of theParticulars
	if (findText is in myInfo) then
		set AppleScript's text item delimiters to findText
		set partialText to text item 2 of myInfo
		set labelLine to paragraph 1 of partialText
		if (labelLine ends with "(") then -- kMDItemAuthors has a 'list' value.
			set AppleScript's text item delimiters to "kMDItem"
			set AuthorsLines to paragraphs 2 thru -3 of text item 1 of partialText
			repeat with thisLine in AuthorsLines
				set thisLine's contents to text from word 1 to word -1 of thisLine
			end repeat
			-- If there's more than one author in the list, line them up with slashes between them.
			set AppleScript's text item delimiters to "/"
			set item i of theParticulars to AuthorsLines as text
		else -- The value's on the same line as the label.
			set AppleScript's text item delimiters to "= "
			set val to text from text item 2 to -1 of labelLine
			-- Put textual quotes round the title and album values if none there. Strip them from anything else if they are.
			if ((findText is "kMDItemTitle") or (findText is "kMDItemAlbum")) then
				if not ((val begins with "\"") and (val ends with "\"")) then set val to "\"" & val & "\""
			else if ((val begins with "\"") and (val ends with "\"")) then
				set val to text 2 thru -2 of val
			end if
			set item i of theParticulars to val
		end if
	else -- Label not found.
		set item i of theParticulars to ""
	end if
end repeat
set AppleScript's text item delimiters to astid

set {songname, songartist, songalbum, songyear, songgenre, songbitrate, samplerate, encoder} to theParticulars

display dialog "Song Name: " & songname & return & return & "Artist: " & songartist ¬
	& return & return & "Album: " & songalbum & return & return & "Year: " & songyear ¬
	& return & return & "Genre: " & songgenre & return & return & "Bitrate: " & songbitrate / 1000 & ¬
	" kb/s" & return & return & "Samplerate: " & samplerate / 1000 & ¬
	" kHz" & return & return & "Encoder: " & encoder

Meanwhile, I’ve been working on a shell-script version today which gets the values of all the returned properties as an AppleScript record, so that other details can be extracted from it too if required:


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 & " |
sed -En ' # Massage the ˜mdls' result into a text representation of an Applecript record.
# For convenience, shorten the property labels by replacing ˜kMDItem' with ˜_'.
s/^kMDItem/_/
# If a line begins with ˜_' and does not end with ˜(':
/^_/ {
    /\\($/ !{ 
        # Replace everything between the label and the value with ˜:' and remove any existing quotes from around the value.
        s/ += \"?/:/
        s/\"$//
        # Add another layer of escape to any remaining quotes in the value.
        s/\"/\\\\\"/g
        # Put doubly-escaped quotes round any ˜_Title' or ˜_Album' value.
        /^_Title:|^_Album:/ s/:(.*)/:\\\\\"\\1\\\\\"/
        # Put ordinary (singly-escaped) quotes round what ever the value is now.
        s/:(.*)/:\"\\1\"/
    }
}
# If a line ends with ˜(' or is ˜)' or is an idented line occurring between such lines:
/\\($/,/^\\)/ {
    # 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.
    /^ / {
	s/^ +\"?|\"?,?$//g
	s/\"/\\\\\"/g
	s/$/\\//
    }
    # If it's the ˜(' line (a label line, beginning with ˜_'), substitute a colon and a quote for everything after the label.
    s/^(_[^ ]+).*/\\1:\"/
    # If it's the ˜)' line, substitute a quote for the ˜)'.
    s/^\\)/\"/
}
# Append whatever's been done to this line above to the hold space.
H
# When the last line's been done:
$ {
    # Retrieve all the edited text from the hold space and put braces round it, ditching an incidental linefeed at the beginning.
    g
    s/^\\n(.*)/{\\1}/
    # Combine the groups of lines formerly between ˜(' and ˜)' lines into single lines.
    s/(\\n_[^:]+:\"|\\/)\\n/\\1/g
    s/\\/\"/\"/g
    # Replace the linefeeds in the rest of text with ˜, '.
    s/\\n/, /g
    # Return the final result to be compiled into an AppleScript record.
    p
}'")

-- Convert the returned "record" text to an actual AppleScript record and concatenate a another record to it with "" values in case the labels which interest us weren't in the text.
set myInfo to (run script myInfo) & {_Album:"", _AudioBitRate:"", _AudioEncodingApplication:"", _AudioSampleRate:"", _Authors:"", _Kind:"", _MusicalGenre:"", _RecordingYear:"", _Title:""}
-- Set variables to the values of interest.
set {_Album:songalbum, _AudioBitRate:songbitrate, _AudioEncodingApplication:encoder, _AudioSampleRate:samplerate, _Authors:songartist, _Kind:encoding, _MusicalGenre:songgenre, _RecordingYear:songyear, _Title:songname} to myInfo

set twoReturns to return & return
display dialog ("Song Name: " & songname & twoReturns) & ¬
	("Artist: " & songartist & twoReturns) & ¬
	("Album: " & songalbum & twoReturns) & ¬
	("Year: " & songyear & twoReturns) & ¬
	("Genre: " & songgenre & twoReturns) & ¬
	("Bitrate: " & songbitrate / 1000 & " kb/s" & twoReturns) & ¬
	("Samplerate: " & samplerate / 1000 & " kHz" & twoReturns) & ¬
	("Encoding: " & encoding & twoReturns) & ¬
	("Encoder: " & encoder)

Edit: Both scripts revised after the discovery of a situation neither could handle properly ” but which axel99092’s script could!

Thank You, that works fine.

I think they do now. I came across an mp3 this afternoon whose album title had quotes in it and non-word characters at each end, causing my first script to display it incompletely and the second to crash. Your script, however, handled it OK. :slight_smile:

I’ve now edited edited the scripts in my post above.

Thank You.

I have extended it to write a new tag and insert a picture.
the existing entries are taken as a suggestion



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 & " |
sed -En ' # Massage the ˜mdls' result into a text representation of an Applecript record.
# For convenience, shorten the property labels by replacing ˜kMDItem' with ˜_'.
s/^kMDItem/_/
# If a line begins with ˜_' and does not end with ˜(':
/^_/ {
    /\\($/ !{ 
        # Replace everything between the label and the value with ˜:' and remove any existing quotes from around the value.
        s/ += \"?/:/
        s/\"$//
        # Add another layer of escape to any remaining quotes in the value.
        s/\"/\\\\\"/g
        # Put doubly-escaped quotes round any ˜_Title' or ˜_Album' value.
        /^_Title:|^_Album:/ s/:(.*)/:\\\\\"\\1\\\\\"/
        # Put ordinary (singly-escaped) quotes round what ever the value is now.
        s/:(.*)/:\"\\1\"/
    }
}
# If a line ends with ˜(' or is ˜)' or is an idented line occurring between such lines:
/\\($/,/^\\)/ {
    # 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.
    /^ / {
	s/^ +\"?|\"?,?$//g
	s/\"/\\\\\"/g
	s/$/\\//
    }
    # If it's the ˜(' line (a label line, beginning with ˜_'), substitute a colon and a quote for everything after the label.
    s/^(_[^ ]+).*/\\1:\"/
    # If it's the ˜)' line, substitute a quote for the ˜)'.
    s/^\\)/\"/
}
# Append whatever's been done to this line above to the hold space.
H
# When the last line's been done:
$ {
    # Retrieve all the edited text from the hold space and put braces round it, ditching an incidental linefeed at the beginning.
    g
    s/^\\n(.*)/{\\1}/
    # Combine the groups of lines formerly between ˜(' and ˜)' lines into single lines.
    s/(\\n_[^:]+:\"|\\/)\\n/\\1/g
    s/\\/\"/\"/g
    # Replace the linefeeds in the rest of text with ˜, '.
    s/\\n/, /g
    # Return the final result to be compiled into an AppleScript record.
    p
}'")
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

(*
set filesize to filesize as integer
set filesize to filesize / 1000 / 1000
set filesize to (round (filesize * 100)) / 100
set songbitrate to songbitrate as number
set songbitrate to (round (songbitrate / 1000))
set twoReturns to return & return

display dialog ("Song Name: " & songname & twoReturns) & ¬
	("Artist: " & quote & songartist & quote & twoReturns) & ¬
	("Album: " & songalbum & twoReturns) & ¬
	("Track Nr.: " & songnumber & twoReturns) & ¬
	("Year: " & songyear & twoReturns) & ¬
	("Genre: " & quote & songgenre & quote & twoReturns) & ¬
	("Comment: " & quote & songcomment & quote & twoReturns) & ¬
	("Bitrate: " & songbitrate & " kb/s" & twoReturns) & ¬
	("Samplerate: " & samplerate / 1000 & " kHz" & twoReturns) & ¬
	("Encoding: " & encoding & twoReturns) & ¬
	("Encoder: " & encoder) & twoReturns & ¬
	("Composer: " & quote & songcomposer) & quote & twoReturns & ¬
	("PhysicalSize: " & filesize & " MB") -- ////////////
*)

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

set mypic to (choose file 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 the text returned of (display dialog "Genre:" default answer 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

heavy!

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