Is anyone able to write an Applescript as the basis to create a droplet app that when I drop a bunch of mp3s on it, it uses the filename pattern "TITLE - ARTIST - YEAR" to change the id3 tags of each file accordingly?
I have a sample of what I was trying to do but keep getting errors:
tell application "Music"
try
-- Get the "Filename Retag" playlist
set playlistName to playlist "Filename Retag"
set filenameRetagPlaylist to playlistName
-- Process each track in the playlist
repeat with aTrack in file tracks of filenameRetagPlaylist
set filePath to location of aTrack
set fileName to name of (info for filePath)
-- Extract data from filename
set textDelimiters to " - "
set textItems to text items of fileName
if (count of textItems) = 3 then
set title to text 1 thru -2 of (item 1 of textItems)
set artist to text 1 thru -2 of (item 2 of textItems)
set year to item 1 of textItems
-- Update track metadata
set name of aTrack to title
set artist of aTrack to artist
set year of aTrack to year
else
do shell script "echo \"Invalid filename format: " & fileName & "\" >> /var/log/system.log"
end if
end repeat
do shell script "echo \"Metadata updated for tracks in playlist \\\"" & playlistName & "\\\".\" >> /var/log/system.log"
on error
do shell script "echo \"Playlist \\\"" & playlistName & "\\\" not found in iTunes.\" >> /var/log/system.log"
end try
end tell
This gives me the error: error "Can’t make «class cUsP» id 2444 of «class cSrc» id 64 of application "Music" into type Unicode text." number -1700 from «class cUsP» id 2444 of «class cSrc» id 64 to Unicode text
I add this code because it might be that I'm really close to a solution but someone can see what I'm doing wrong!
For a droplet, the items would need to be added to the music library, unless they have already been added to the "Filename Retag" playlist. Note that the name of a file path also includes the extension, so if you are going that route, the extension would need to be removed when working with the name pattern.
playlistNamevariable is set to a playlist, butfilenameRetagPlaylistis also set toplaylistName, so it looks like those two statements got mixed up and should have been:info foris also not needed, as a track has anameproperty;textDelimitersvariable, you should be settingAppleScript’s text item delimitersproperty;name,artist,year, etc. In this case they can all be set with a single statement.Your posted script, cleaned up a little and with more error handling, would look something like: