Does any know know of a script (free if possible) that can export the content of a smart playlist/playlist to the finder?
thanks
Does any know know of a script (free if possible) that can export the content of a smart playlist/playlist to the finder?
thanks
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.
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
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
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:
[format]tell playlist (get (choose from list (get user playlists’s name))'s item 1) to repeat with aTrack in tracks[/format]
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. Have the selected playlist export? How would I do that?
@slashdot, hi.
Simply replace in the script of Mark Anthony
tell playlist “Enya”
with
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.
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
It works when some song plays. So, select manually some playlist, run this script:
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
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.
Hi, again.
I forgot you want the files and not the info of them. Use this:
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
Thanks! it worked. Appreciate it.
Advanced version, assuming playlist is chosen already as well:
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
Next version uses choose dialogs to select playlist:
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"
that’s sweet! I’d definitely look forward to a script that does work with both smart and regular playlist.
This is good just some feedback for your consideration:
Feedback for your consideration.
So, it seems I was quick to declare that my latest version of the script with smart playlists does not work - it does. I updated my last script’s post (post #14).
Completed version of the script for exporting playlists to Finder.
Exports to the “Exported Playlists” folder on the desktop, also added the ability to select multiple playlists at once.
tell application "Music" -- or "iTunes"
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(s)" with multiple selections allowed
if theChoice is false then return
set playlistsFolder to my makeDestinationRootFolder()
repeat with i from 1 to count theChoice
set selectedPlayList to playlist (item i of theChoice) of source theSourceName
if (count (get tracks of selectedPlayList)) > 0 then
set fileLoci to {}
try
set view of front browser window to selectedPlayList
set visible of front browser window to true
end try
set playlistName to "playlist \"" & name of selectedPlayList & "\""
say "Exporting " & playlistName
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
set currentFolder to my makeDestinationPlaylistFolder(playlistName)
tell application "Finder" to duplicate fileLoci to currentFolder
end if
end repeat
quit
end tell
on makeDestinationPlaylistFolder(playlistName)
tell application "Finder"
try
set currentFolder to make new folder at folder "Exported PlayLists" of desktop with properties {name:playlistName}
on error
set currentFolder to folder playlistName of folder "Exported PlayLists" of desktop
end try
end tell
return currentFolder
end makeDestinationPlaylistFolder
on makeDestinationRootFolder()
tell application "Finder"
try
set f to make new folder at desktop with properties {name:"Exported PlayLists"}
on error
set f to folder "Exported Playlists" of desktop
end try
end tell
return f
end makeDestinationRootFolder
Thanks a lot for knocking this out. Appreciate the hard work!
Picking back up on this to ask if anyone knows how I can adapt the suggested script solutions above from @KniazidisR & @slashdot to create a script that will batch export my entire Music Library’s playlist collection - ideally into the Playlist Folders they’re organised in - as .m3u files?