How to add a track to Library in Apple Music using Apple Script

applescriptitunesmusic

I searched through a few posts online and most of them say to use this:

tell application "Music"
    duplicate current track to source "Library"
end tell

…but I get the following error:

"Music got an error: Can’t set source \"Library\" to current track." number -10006 from source "Library"

Did Apple change/remove adding a track to the Library? I can't find any update on this and Apple's docs on this are nonexistent.

Best Answer

I'm not in front of a Mac at the moment, so can't test this, but what happens if you try the following:

tell application "Music"

    set newFile to (choose file with prompt "Select track you want to add...")

end tell

Of course, you can change the 'prompt' text to whatever you want.

Also, in case you're wanting to, you should be able to get the script to add the track to a specific playlist by adding the following line after the set newFile line:

add newFile to playlist "Newly added tracks"

Of course, you can change the 'playlist' name by changing the text within the quotation marks to whatever you want.

Related Question