FixLinks - an AppleScript to repair broken links in Music

I am using this script by @turingtest2 to rebuild my music library after my drive /+ time machines failed.


FixLinks - an AppleScript to repair broke… - Apple Community


Current status my end:


  • I have salvaged the .musiclibrary file.


  • I have salvaged my music although It is from a USB that has been processed in another software. Therefore on tracks where the album field is blank there is a subfolder called 'unknownalbum'. It also truncates all file names to 48 characters


My iTunes library didn't work this way it expects files to be in the file under the artist name and not one level lower in a folder called 'unknownalbum' and also is looking for the full non truncated name


When I run the script I get a message pop up saying that the media cannot be found although the file path the script has given in the message is now corrected all bar the truncated name


What can I tweak to bypass this message and apply a truncation rule?


Running Catalina 10.15.17





Posted on Oct 15, 2022 1:31 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 15, 2022 2:36 PM

Hi,


I'm not quite clear where your Unknown Album tracks are, a folder called UnknownAlbum (without a space) or in the main artist folder? Either way you can adjust this line to match your layout for the first issue, or indeed other special cases with album titles:


if theAlbum = "" then set theAlbum to "Unknown Album"


If there is no separate album folder in the layout at all then this line:


set newPath to theArtist & "/" & theAlbum & "/" & theFile


should be edited to:


set newPath to theArtist & "/" & theFile -- Option for no album folder




To deal with the truncated filenames insert this block:


if length of theFile > 44 then

set theFile to text 1 thru 44 of theFile

end if


immediately before this line:


-- extend this pattern as required


(44 because we're going to add a 4-letter file extension to get to your count of 48, again one could tweak as needed.)



I haven't actually tried out these changes live so it is possible I've missed something. AppleScript isn't the main language I work in. Let me know how you get on and if needs be I'll set things up in parallel here so I can reproduce the conditions properly for testing.



tt2

9 replies
Question marked as Top-ranking reply

Oct 15, 2022 2:36 PM in response to Rinco11

Hi,


I'm not quite clear where your Unknown Album tracks are, a folder called UnknownAlbum (without a space) or in the main artist folder? Either way you can adjust this line to match your layout for the first issue, or indeed other special cases with album titles:


if theAlbum = "" then set theAlbum to "Unknown Album"


If there is no separate album folder in the layout at all then this line:


set newPath to theArtist & "/" & theAlbum & "/" & theFile


should be edited to:


set newPath to theArtist & "/" & theFile -- Option for no album folder




To deal with the truncated filenames insert this block:


if length of theFile > 44 then

set theFile to text 1 thru 44 of theFile

end if


immediately before this line:


-- extend this pattern as required


(44 because we're going to add a 4-letter file extension to get to your count of 48, again one could tweak as needed.)



I haven't actually tried out these changes live so it is possible I've missed something. AppleScript isn't the main language I work in. Let me know how you get on and if needs be I'll set things up in parallel here so I can reproduce the conditions properly for testing.



tt2

Oct 15, 2022 2:57 PM in response to turingtest2

Thanks for the quick reply,


The 'UnknownAlbum' is within the main artist folder. So amended


if theAlbum = "" then set theAlbum to "Unknown Album"


to


if theAlbum = "" then set theAlbum to "UnknownAlbum"



Added the truncate line also and appears to be working like a charm now. Thank you!!


I have a lot of files (5k+) to process through can you tell me the line to decativate the 'file not found at' popup showing as I am getting a few where it can't find the song because I have changed the artist name in music app for whatever reason. I can find these manually afterwards


Oct 17, 2022 12:01 PM in response to turingtest2

All done the script picked up around 4200 of the mismatches fine. I did the other 800 manually as there were a lot of quirks causing it to trip up. Nice way to spend an afternoon!


Thank you for writing this script tt2 it has saved me weeks of work and pain.


Only issue with the library / music app now is that all album art is showing ok when I select 'get info' but if I'm playing a track it doesn't appear in the top viewer anymore. Nor anywhere else where it is displayed only in 'get info'

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

FixLinks - an AppleScript to repair broken links in Music

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.