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.