Sunday, June 13, 2021

#1 2021-05-07 06:26:44 am

daBee
Member
From:: Toronto
Registered: 2010-02-09
Posts: 161

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.  <snicker>

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


Filed under: music, playlists, big sur

Offline

 

#2 2021-06-08 07:28:40 pm

daBee
Member
From:: Toronto
Registered: 2010-02-09
Posts: 161

Re: Music App from Text File

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

Offline

 

#3 2021-06-09 04:37:14 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 40

Re: Music App from Text File

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…

Applescript:

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:

Applescript:

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…

Applescript:

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:

Applescript:

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.

Offline

 

#4 2021-06-09 08:50:39 am

daBee
Member
From:: Toronto
Registered: 2010-02-09
Posts: 161

Re: Music App from Text File

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

Offline

 

#5 2021-06-09 01:47:14 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 40

Re: Music App from Text File

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

Offline

 

#6 2021-06-09 01:53:04 pm

daBee
Member
From:: Toronto
Registered: 2010-02-09
Posts: 161

Re: Music App from Text File

Heh.  They should fix Mail.app as well.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)