Monday, September 28, 2020

#1 2020-02-14 03:52:23 am

Jono
Member
Registered: 2008-07-08
Posts: 120

Apple Music: Set variable to playlist of selected track

As part of another script I'm trying to write, I'm trying to get the playlist (name or reference) of the track currently selected in Apple Music and set it as a variable. Here are some things I've tried:


Applescript:

tell application "Music"
   set selectedTrack to selection
   
   set selectedPlaylist to (get playlist id of selection)
   -- set selectedPlaylist to (get playlist of selection)
   -- set selectedPlaylist to (get user playlist id of selection)
   -- set selectedPlaylist to (get user playlist of selection)
   log selectedPlaylist
   
end tell

Hoping it's quite simple for someone who actually knows what they're doing smile

Offline

 

#2 2020-02-14 05:27:59 am

alastor933
Member
From:: Utrecht, NL
Registered: 2008-09-12
Posts: 576

Re: Apple Music: Set variable to playlist of selected track

First, selection is a list, so you'd get its item 1.
Then, looking at the application dictionary (did you do that?) I see that file track inherits from track > item.
And item has a property container.
So:

Applescript:

tell application "iTunes"
   set selectedTrack to item 1 of (get selection)
   -->file track id 3243 of user playlist id 2813 of source id 66 of application "iTunes"
   set pl to container of selectedTrack
   --> user playlist id 2813 of source id 66 of application "iTunes"
   properties of pl
   --> {class:user playlist, id:2813, index:2, name:"Muziek", persistent ID:"038DE205151B8651", duration:178155, size:2.9401292144E+10, time:"2:01:29:15", visible:true, special kind:Music, loved:false, disliked:false, smart:true, shared:false, genius:false}
end tell

This should work when you change 'iTunes' to 'Music'. If it doesn't you should log a bug with Apple.
Can do?

Offline

 

#3 2020-02-14 08:18:44 am

Jono
Member
Registered: 2008-07-08
Posts: 120

Re: Apple Music: Set variable to playlist of selected track

Thanks a lot, that's a great help!

I looked at the dictionary for Music, but (as I don't know so much AppleScript) didn't understand it enough to work it out on my own smile

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)