Sunday, June 13, 2021

#1 2021-06-01 02:50:04 pm

slashdot
Member
Registered: 2003-11-13
Posts: 298

music - Export files from a playlist/smart playlist to finder

Does any know know of a script (free if possible) that can export the content of a smart playlist/playlist to the finder?

thanks

Offline

 

#2 2021-06-01 05:10:59 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1026

Re: music - Export files from a playlist/smart playlist to finder

Hi. It's unclear if by 'content' you mean the track metadata or the actual files. The latter could be cripplingly time-consuming, but can be affected by re-enabling the commented out sections.

Applescript:


set trackData to {}
--set fileLoci to {}
tell application "iTunes" --or "Music"
   tell playlist "Enya" to repeat with aTrack in tracks
       tell aTrack
           set trackData's end to {artist, "—", album, ": ", name} & return
           --set fileLoci's end to its location
       end tell
   end repeat
end tell
set trackData to trackData as text
tell application "Finder"
   write my trackData to ((make file) as alias)
   --duplicate fileLoci to choose folder
end tell

Offline

 

#3 2021-06-01 06:21:08 pm

slashdot
Member
Registered: 2003-11-13
Posts: 298

Re: music - Export files from a playlist/smart playlist to finder

I was talking about actual files.  Sorry I wasn't clear. Thanks for pointing it out.

Thats great!  It works!

Is there a way to select a playlist and not specify the name of the playlist in the list?

thanks

Last edited by slashdot (2021-06-01 06:21:39 pm)

Offline

 

#4 2021-06-01 06:58:54 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1026

Re: music - Export files from a playlist/smart playlist to finder

You can specify them by index; e.g. 'playlist 2", but that requires knowing the item's position; it's probably safer to use a name, and you could choose it:

tell playlist (get (choose from list (get user playlists's name))'s item 1) to repeat with aTrack in tracks

Last edited by Marc Anthony (2021-06-01 07:06:31 pm)

Offline

 

#5 2021-06-03 03:57:48 am

slashdot
Member
Registered: 2003-11-13
Posts: 298

Re: music - Export files from a playlist/smart playlist to finder

Marc Anthony wrote:

You can specify them by index; e.g. 'playlist 2", but that requires knowing the item's position; it's probably safer to use a name, and you could choose it:

tell playlist (get (choose from list (get user playlists's name))'s item 1) to repeat with aTrack in tracks



Thanks for sharing this addition to the already useful script but I understand error on the side of being careful but what if I want to live dangerously. smile Have the selected playlist export?  How would I do that?

Offline

 

#6 2021-06-04 12:49:35 am

technomorph
Member
Registered: 2017-12-14
Posts: 184

Re: music - Export files from a playlist/smart playlist to finder

Check out dougscripts.com

All the bits and pieces you need are there

Offline

 

#7 2021-06-04 01:44:22 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1878

Re: music - Export files from a playlist/smart playlist to finder

@slashdot, hi.

Simply replace in the script of Mark Anthony

tell playlist "Enya"

with

tell current playlist

It is your manually selected playlist.

Last edited by KniazidisR (2021-06-04 01:45:25 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#8 2021-06-11 06:31:11 am

slashdot
Member
Registered: 2003-11-13
Posts: 298

Re: music - Export files from a playlist/smart playlist to finder

KniazidisR wrote:

@slashdot, hi.

Simply replace in the script of Mark Anthony

tell current playlist

It is your manually selected playlist.



Hi, thanks you for the reply but unfortunately when doing this for music app it runs but nothing happens.


Applescript:

set trackData to {}
--set fileLoci to {}
tell application "Music" --or "Music"
   tell current playlist to repeat with aTrack in tracks
       tell aTrack
           set trackData's end to {artist, "—", album, ": ", name} & return
           --set fileLoci's end to its location
       end tell
   end repeat
end tell
set trackData to trackData as text
tell application "Finder"
   write my trackData to ((make file) as alias)
   --duplicate fileLoci to choose folder
end tell

Not sure if you tired it on iTunes app but the music app it doesn't work for macOS 10.15 - catalina

Last edited by slashdot (2021-06-11 07:42:10 am)

Offline

 

#9 2021-06-11 08:12:10 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1878

Re: music - Export files from a playlist/smart playlist to finder

It works when some song plays. So, select manually some playlist, run this script:

Applescript:


set trackData to {}
--set fileLoci to {}
say "Exporting current palylist's info" -- ADDED

tell application "Music" --or "Music"
   play -- ADDED
   delay 0.1 -- ADDED
   tell (get current playlist) to repeat with aTrack in tracks -- EDITED
       tell aTrack
           set trackData's end to {artist, "—", album, ": ", name} & return
           --set fileLoci's end to its location
       end tell
   end repeat
   stop -- ADDED
end tell
set trackData to trackData as text
tell application "Finder"
   write my trackData to ((make file) as alias)
   --duplicate fileLoci to choose folder
end tell

Last edited by KniazidisR (2021-06-11 08:33:07 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#10 2021-06-11 10:30:16 pm

slashdot
Member
Registered: 2003-11-13
Posts: 298

Re: music - Export files from a playlist/smart playlist to finder

Hi KniazidisR...

thanks for responding.  It's greatly appreciated. However, I think the script you're sharing is exporting the playlist data like albums and songs. 

what I was asking for is to export the files in a playlist itself to a specified destination.

The script you provided does work to export the playlist album and song names but I'm looking for the ability to export the files to a folder of my choosing.

Offline

 

#11 2021-06-11 11:44:32 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1878

Re: music - Export files from a playlist/smart playlist to finder

Hi, again.

I forgot you want the files and not the info of them. Use this:

Applescript:


set fileLoci to {}
say "Exporting current playlist's files" -- ADDED

tell application "Music" --or "Music"
   play -- ADDED
   delay 0.1 -- ADDED
   tell (get current playlist) to repeat with aTrack in tracks -- EDITED
       tell aTrack
           if (get its location) is missing value then
               -- do nothing
           else
               set fileLoci's end to its location
           end if
       end tell
   end repeat
   stop -- ADDED
end tell

tell application "Finder" to duplicate fileLoci to choose folder

Last edited by KniazidisR (2021-06-11 11:53:35 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#12 Yesterday 02:12:52 am

slashdot
Member
Registered: 2003-11-13
Posts: 298

Re: music - Export files from a playlist/smart playlist to finder

Thanks! it worked.  Appreciate it.

Offline

 

#13 Yesterday 10:57:09 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1878

Re: music - Export files from a playlist/smart playlist to finder

Advanced version, assuming playlist is chosen already as well:

Applescript:


set fileLoci to {}

tell application "Music" --or "iTunes"
   play
   set currentPlaylist to current playlist
   stop
   set playlistName to "playlist \"" & name of currentPlaylist & "\""
   say "Exporting " & playlistName & "'s files"
   tell currentPlaylist to repeat with aTrack in tracks
       tell aTrack to if not ((get its location) is missing value) then set fileLoci's end to its location
   end repeat
end tell

tell application "Finder"
   try
       set playlistsFolder to make new folder at (path to music folder) with properties {name:"Exported PlayLists"}
   on error
       set playlistsFolder to folder "Exported Playlists" of folder "Music" of home
   end try
   try
       set currentPlaylistFolder to make new folder at playlistsFolder with properties {name:playlistName}
   on error
       set currentPlaylistFolder to folder playlistName of folder "Exported Playlists" of folder "Music" of home
   end try
   duplicate fileLoci to currentPlaylistFolder
end tell

Last edited by KniazidisR (Yesterday 11:25:31 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#14 Yesterday 11:23:14 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1878

Re: music - Export files from a playlist/smart playlist to finder

Next version uses choose dialogs to select playlist:

Applescript:


set fileLoci to {}

tell application "Music" -- or "iTunes"
   -- choose playlist
   set sourcesNames to name of every source
   set theChoice to choose from list sourcesNames with prompt "PLEASE SELECT THE SOURCE"
   if theChoice is false then return
   set theSourceName to item 1 of theChoice
   set playlistNames to name of every playlist of source theSourceName
   set theChoice to choose from list playlistNames with prompt "PLEASE SELECT THE PLAYLIST"
   if theChoice is not false then
       set selectedPlayList to playlist (item 1 of theChoice) of source theSourceName
       set view of front browser window to selectedPlayList
       set visible of front browser window to true
   end if
   
   set playlistName to "playlist \"" & name of selectedPlayList & "\""
   say "Exporting " & playlistName & "'s files"
   tell selectedPlayList to repeat with aTrack in tracks
       tell aTrack to if not ((get its location) is missing value) then set fileLoci's end to its location
   end repeat
   
end tell

tell application "Finder"
   try
       set playlistsFolder to make new folder at (path to music folder) with properties {name:"Exported PlayLists"}
   on error
       set playlistsFolder to folder "Exported Playlists" of folder "Music" of home
   end try
   try
       set currentPlaylistFolder to make new folder at playlistsFolder with properties {name:playlistName}
   on error
       set currentPlaylistFolder to folder playlistName of folder "Exported Playlists" of folder "Music" of home
   end try
   duplicate fileLoci to currentPlaylistFolder
end tell

tell application "Music" to quit -- or "iTunes"

NOTE: this version will work with real playlists, not with smart playlists.

Last edited by KniazidisR (Yesterday 11:36:52 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)