Music App from Text File

Hiya folks. Moved to Big Sur and sussing out the issues.

Moving my playlists from El Capitan to Big Sur is a bit of a pain. For some reason some tunes aren’t showing up in exported playlists that are a text file. The migration is too long for anything rational…from Apple.

So I have written a Ruby script to suss out what tunes are missing, from the playlist text exports. It iterates through the old playlist, and checks to see if it’s in the new playlist. Again, both are playlist text exports.

How can I script the following:

  1. Copy the highlighted text track name to the clipboard
  2. Activate the Music.app, and search for that track name

I can manually drag it over, but all the manual stuff is a complete drag.

I can’t find any way of entering the clipboard content into the search field, and perform the search. Or any other way of achieving this.

Any insight appreciated. Cheers

Model: Mac Mini M1
AppleScript: Big Sur
Browser: Latest Chrome
Operating System: Other

Seems the whole music thing and iTunes have been separated and fallen behind.

I’m not sure what app you’re working in to get the ‘highlighted track’. Is it itunes? I’ll assume that you’re working with the itunes and music apps (but below is if it’s a text editor). Advise if it is otherwise.

I’m on Sierra so I don’t have Music but assuming its applescript library is similar to itunes, something like this might work.

Begin with a single selected track in itunes…

tell application "iTunes"
	activate
	set il1 to library playlist 1
	set inn to name of selection as text
	set the clipboard to inn
end tell

If you actually have a track title on the clipboard, then:

set inn to the clipboard

If it’s in a text editor but not on the clipboard, then you’ll have to provide more detail.

Then search for that track name in Music…

tell application "Music"
	activate
	
	-- get the music playlist
	set ml1 to user playlist 1
	-- search the music playlist for name of track
	set strk to search ml1 for inn
	
	reveal item 1 of strk	
end tell

You may have multiple results with the same song title. ‘Reveal’ will select the referenced song, but it may not be the one you’re after, so you’ll need to deal with that if it’s an issue. You can get the properties of a track (e.g. properties of selection) and perhaps there is information there to control which result should be worked with. For example, this would provide the album for each found track:

set alb to {}
	repeat with x in strk
		set end of alb to album of x
	end repeat
	--> {"The Beatles (White Album)", "Past Masters, Vols. 1 & 2"}

Some terminology (from itunes, music may not be identical):
‘library playlist’ is the ‘library’ and is a special sort of playlist.
‘user playlist’ is both the ‘media kind’ (e.g. Music, Podcasts) as well as the playlists you create. By default, ‘Music’ is ‘user playlist 1’ but you can ‘get playlists’ or ‘get user playlists’ for a list of them to confirm.

I’ve solved it inside the Music app, which replaces iTunes for music. Not sure if it was in Catalina or Big Sur, but it’s that app now.

I was trying to iterate through the tunes and take out the element for artwork, but it’s something that can be accomplished in the app itself.

Cheers

Glad to hear it. Something like that should be built-in. Apple should do more stuff like that.

Heh. They should fix Mail.app as well.