0

I have an AppleScript, which duplicates the currentTrack to my AppleMusic Library. Although, it seems that the Library has a capacity of (length of the library + 1), and whenever I add a new track using the duplicate this capacity is not increased. This means, that whenever I try to add another track, it doesn't work. Although, if I remove any other item, then 1 capacity is freed, and I can add another track to my Library.

If I manually add another track to the Library using the Apple Music app, then the capacity is updated, and I can add another track using the AppleScript script.

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

Update: the snippet below seems to be working (it's JXA tho). The duplicate method is not returning the added track (just true), probably because it's an async operation. That's why the delay. Not sure if there's a better way to achieve the same, my knowledge of this is a bit limited.
Bonus: Changing the rating of the added item.

var music = Application("Music")
var app = Application.currentApplication()
app.includeStandardAdditions = true

var track = music.currentTrack
track.loved = true

var myLib = music.sources['Library']
track.duplicate({ to: myLib })

delay(4)

myLib.tracks().find(t => t.name() === track.name() && t.artist() === track.artist()).rating = 100

Update 2: The one above does not work if I Create Station.... It works as expected if I play any of the Playlists available in the Browse section. I'm starting to see a pattern here... it looks like I can only add to my Library the tracks that belong to a Playlist. I've compared the properties of the same song when played using the Create Station and from another playlist. The only relevant difference is the IDs of both, their databaseID and persistentId are different. So my assumption is that this is the reason.

Update3: this blog post explains a lot the situation above.

KadoBOT
  • 2,944
  • 4
  • 16
  • 34
  • What is your AppleScript looking like ? – Chino22 Jul 06 '22 at 17:00
  • I have added the code snippet. Although, for some reason, I was able to add a few songs. But this already happened, and it seems to work sometimes. And other times, it doesn't. – KadoBOT Jul 07 '22 at 03:00
  • As far as I understand, the Music application's **duplicate** command does not physically write a new copy to the library folder on disk. It just creates a new link to the original, understandable to the application. Therefore, the size of the library does not increase. The equivalent of manually adding a song (that is, the equivalent of physically writing to disk) is the **add** command, not the **duplicate** command. And the **add** command adds only existing files of your file system as I understand. – Robert Kniazidis Jul 07 '22 at 04:00
  • I've managed to get it working (magic?!), and it even syncs with the cloud, so there's an async operation before it's actually added. – KadoBOT Jul 07 '22 at 04:02

0 Answers0