2

I can export a single playlist from iTunes to m3u format easily enough, but is there any way to do it en masse? I have about 40 playlists and it's exceedingly tedious to do it for all of them one at a time. I know you can dump the entire library database if you're just switching between macs but I use these all over the place. That library file is megabytes and megabytes and while I could conceivably reconstruct my playlists from the xml plist it's not ideal.

4 Answers 4

1

Just using iTunes by itself, I do not know of a way to export multiple playlists at the same time, as one can only select one playlist in the Sidebar at a time.

Normally to export a playlist in iTunes one would, e.g., select the target playlist in the Sidebar and then click: File > Library > Export Playlist…

This then brings up a Save dialog box, e.g.:

enter image description here

To semi-automate the process I assigned a keyboard shortcut of ⌘E to the Export Playlist… in System Preferences > Keyboard > Shortcuts > App Shortcuts, as shown the image below.

This allows me to easily bring up the Save dialog box without having to navigate the menus, and I can then just use the keyboard to easily walk through saving one playlist after the other.

It's easy to get into a rhythm, select the first playlist, then ⌘E > enter > down-arrow > ⌘E > enter > down-arrow > etc.

enter image description here


To further semi-automate the process, you can use a bit of AppleScript in Script Editor.

Example AppleScript code:

activate application "iTunes"
delay 1
tell application "System Events"
    repeat 1 times
        keystroke "e" using command down
        delay 0.5
        key code 36 # return key
        delay 0.5
        key code 125 # down-arrow key   
        delay 0.5
    end repeat
end tell

Change repeat 1 times to the number of times you want it to repeat.

Then in iTunes select the first playlist on the Sidebar and then run the script from Script Editor.

This example AppleScript code assumes you've already once selected the Where: and Format: and will use the default names in the Save As:, none of which are the same, and there are no playlists currently at the Where: that would interfere with the limited example AppleScript code. Otherwise, additional coding will be necessary.

If you want to use the example AppleScript code without assigning a keyboard shortcut for the Export Playlist… command, then in place of keystroke "e" using command down use:

    click menu item "Export Playlist…" of ¬
        menu "Library" of ¬
        menu item "Library" of ¬
        menu "File" of ¬
        menu bar item "File" of ¬
        menu bar 1 of ¬
        application process "iTunes"

Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

2
  • Keyboard shortcut idea is definitely helpful, that's way faster than using the trackpad. Jun 26, 2020 at 13:22
  • 1
    @Jared Smith, I've added a bit of AppleScript to further semi-automate the process. Jun 26, 2020 at 14:02
0

Here my applescript with some changes because the down-arrow key approach was not working very well.

activate application "Music"
delay 1

tell application "Music"
    set playlistArray to (get name of every playlist)

    # Foreach playlist...
    repeat with currPlaylist in playlistArray

        if ( (currPlaylist as string) is not equal to "Libreria" and (currPlaylist as string) is not equal to "Musica" ) then
            say currPlaylist
            tell application "Music"
                # Set the current playlist in the sidebar
                set the view of the front browser window to playlist (currPlaylist as string)
                delay 1

                # Start export
                tell application "System Events"
                    keystroke "e" using command down            # it's necessary to have set the shortcut CMD+E
                    delay 2                                     # delay in seconds
                    key code 36                                 # simulation return key
                    delay 2
                end tell

            end tell

            delay 0.5
        end if
        
    end repeat
end tell

To execute it from the terminal: osascript ~/Desktop/automate_export_playlist.scpt

0

I ended up writing a CLI utility to extract them from the Library.xml

https://github.com/jasmith79/playlistrs

If anyone else is interested. I used the custom solution mostly because it allowed me to tweak the path during processing for other devices and whether to use raw paths or file URLs.

0

borrowing off of @suikoy

I wanted a way to have a select few playlists to export, not export every single playlist

I manually set the playlistArray to an array of strings.

log "--- Start Playlist Export ---"

activate application "Music"
delay 1

tell application "Music"
    set playlistArray to {"bangersonly", "playlist2", "playlist3"}
    log "Selected Playlists"
    log playlistArray
    set allPlaylistArray to (get name of every playlist)
    log "All Playlists"
    log allPlaylistArray
    
    # Foreach playlist...
    repeat with currPlaylist in playlistArray
        
        if playlistArray contains currPlaylist then
            say currPlaylist
            tell application "Music"
                # Set the current playlist in the sidebar
                set the view of the front browser window to playlist (currPlaylist as string)
                delay 1
                
                # Start export
                tell application "System Events"
                    keystroke "e" using command down # it's necessary to have set the shortcut CMD+E
                    delay 2 # delay in seconds
                    key code 36 # simulation return key
                    delay 2
                end tell
                
            end tell
            
            delay 0.5
        end if
        
    end repeat
end tell

log "--- Playlist Export Complete ---"

English edits

Libreria = Library Musica = Music

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .