3

I've got a little AppleScript in Alfred that marks the currently-playing song as "Loved", it looks like this:

tell application "iTunes"
    set loved of current track to true
end tell

This script works great.

But! I'd like it to do one more thing, and it's not working: I'd like to add the track to a playlist called "Loved". Here's v2 of the script:

tell application "iTunes"
    set loved of current track to true
    duplicate current track to playlist "Loved"
end tell

This way, I'd have a way to find these tracks later (for example, I listen to Radio a lot, and would love to find those Favorites later on).

Here is the error message that AppleScript shows me when I run v2:

"iTunes got an error: Can only duplicate subscription tracks to library source."

Any ideas if there is a way to accomplish this?

A few caveats:

  • I'd like to avoid adding the track to my Library.
  • If there's a way to have a Smart Playlist that contains all songs that I've Loved (even those not in my Library), then great! As far as I can tell, though, that's not possible with Smart Playlists.
1

I've been cracking my head on this one as well and currently, there doesn't seem to be any way to add Apple Music tracks to a playlist. It's kinda unintuitive that there isn't a default way in AM to access all loved songs, but here we are. AM is getting better surely but slowely, so fingers crossed.

What I've done as a workaround in the meantime, is added a functionality that saves the song into a text file that is synced to iCloud. That way I can manually enter the songs whenever I have some time to spare and I can do it both on my iMac and Macbook.

tell application "iTunes"
    set loved of current track to true
    set songname to current track's name
    set songartist to current track's artist
    set textpath to "~/Library/Mobile\\ Documents/com~apple~CloudDocs/AppleMusicToDo.txt"

    do shell script "echo " & quoted form of songartist & " - " & quoted form of songname & " >> " & textpath

end tell
1

It seems your code works if you use it with songs that are already in your library. Therefore if you use some AppleScript code to add the song to your library beforehand, your code should work. Here's some AppleScript I came up with to add a song to your library: Add currently playing song to Apple Music using AppleScript Editor

  • (Thanks for your suggestion, but I'm explicitly looking for a way to do this without adding the track to my Library - see the "caveats" in the question above.) – bryanjclark Oct 16 '18 at 17:01
  • Ah, sorry to be the guy who didn't read the question properly, but theoretically, you might be able to tweak my script to remove the song from your library after adding it to the playlist; I believe the song not being in the library is the reason your script doesn't function as expected. – jackgmarch Oct 17 '18 at 18:05
  • Ah, neat idea! I'll give it a shot :D – bryanjclark Oct 19 '18 at 0:36
0

There's a better approach:

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

(took it from here)

Used it just now, works pretty well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .