Export iTunes Playlist to M3U

This page describes an AppleScript that I put together to generate a .m3u format playlist file from an iTunes playlist suitable for use with the AudioTron. If you own an AudioTron and use a Macintosh running Mac OS X 10.2 or higher with iTunes 3 or 4 as your ripper/encoder/librarian and you use Samba to serve up your MP3 files to your AudioTron, then this script is for you.

Copyright / License

Copyright (C) 2002-2003 Bery Rinaldo

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Updates

DateVersionDescription
29-Apr-20036Added support for iTunes 4.
4-Mar-20035.1Made string search case insensitive to fix issues with some users.
12-Feb-20035.0Added external Perl script to parse iTunes database, handles all long names properly now.
14-Dec-20024.0Handle URL tracks properly, added "wizard setup" for first run, settings file support, deal better with long names on SMB mounts and added GPL notice.
03-Dec-20023.0Fixed 31 character filename limitation. Now long filenames are output properly.
21-Mar-20022.0Added optional status indicator using shuffle indicator
18-Mar-20021.0Initial release

Credits

Very special credit to Paul Withey who authored the Playlist Summary script where I borrowed from heavily (read: copied) to make this script work. Another special credit and thanks to Doug Adams and his Doug's AppleScript web site from which I borrowed (read: copied) the following iTunes Setup section. Thanks to Dave Ray for his instructions on how to use Export Playlist to M3U with an Archos Jukebox.

Also, you should visit the Mac OS X / AudioTron Page for more details on using your Mac and AudioTron together.

iTunes Setup

iTunes versions 2 and higher are what's known as "attachable". It has a Scripts Menu in its Menu Bar from which you can run AppleScripts. But you wouldn't know it at first glance. That's because you have to set it up.

For users of OS X: to make AppleScripts available to all Users, create a folder called "Scripts" and place it in Library > iTunes (you may have to create the "iTunes" folder; I think you can put the "iTunes Plug-Ins" folder here also). For single Users, make a "Scripts" folder in the Users > username > Library > iTunes folder. Put your scripts in the "Scripts" folder and they will appear in iTunes' Scripts Menu.

You can also create a "Scripts" folder in the Documents > iTunes folder. This is considered the "per-user" folder while the one in the iTunes application folder is global to all users.

The Script

I have provided a link to a StuffIt archive which contains a text version of the script, HTML documentation, GPL.txt license information and the application.

After downloading and unstuffing, you should put the two files in the Scripts folder you created as part of the setup instructions above. The picture below shows the path to the script under a user account folder.

First Run (Wizard Setup)

When you first run the application (either from iTunes or the Finder) you will be walked through the process of setting up the mappings between paths on the Mac and the paths that the AudioTron uses (via Samba aka Windows File Sharing). The following dialog is displayed.

Choose the Use Wizard button to walk through this mapping process. You will then be prompted to choose a folder on your Mac that the AudioTron accesses.

Navigate to the folder (such as Music as shown) then click on the Choose button. Next, you will be prompted to enter the path that the AudioTron uses to access that directory on your Mac.

Type in the first part of the path that the AudioTron uses to access this folder. This path name is in the UNC format starting with 2 backslashes and the server name followed by the share name, then most likely a folder name. If you're unsure about what to enter here, see the next section for an example. After entering the path, click OK and you will be asked if you have any more mappings to enter.

If you do have a more complex network setup where you need more mappings, click on Yes and you will be prompted to choose another folder on your Mac as above. Most of the time, there will only be one mapping, so you may choose No and continue on. The next prompt you will choose whether or not you want this shuffle indicator while the script is running.

If you export long lists, then having some sort of indication that the script is doing something may be important to you, so choose Yes. This does have the side effect of turning on fixed indexing so that the output order in the file may not match the displayed order because it uses the original order the songs were added to the playlist. If output order is important to you, then choose No. Choose your preference and then you will be prompted to save these settings in a file.

After the settings file has been saved, the following dialog is displayed.

The settings file can be used when future versions of the script are released so that you don't have to go through the wizard setup process next time.

An Example

Here is a more detailed example of how one might set things up for their needs. This section provides a more detailed explanation of what is needed for a simple mapping of a single directory that is used for iTunes and shared via Samba.

The folder you choose on the Mac is the highest level that is shared with the AudtioTron. You can see the full path to files in iTunes when you click on a song, then do "File->Get Info" under the "Info" tab, under General Information you will see the Mac pathname next the the "Where:" field. This will be something like this:

Macintosh HD:Users:username:Music:Artist:Album:Song.mp3

Then compare that to what the AudioTron uses for the path to the same song. This will help you fill in the PC-style UNC pathname that maps to the same folder on your Mac. To see the path names the AudioTron uses, open up the web interface when the AudioTron is playing that same song, then click on the field next the "Location:" that says "Click here for file location" which will show you something like this:

\\SERVER\username\Music\Artist\Album\Song.mp3

Now you're armed with the information you need to get things setup. The first step is choosing the folder on your Mac. In this case, choose the Music folder under Macintosh HD:Users:username. Next, you would enter \\SERVER\username\Music for the path that the AudioTron uses to access that same folder.

If you had multiple shares in Samba, or more than one mounted network drive, then you might need more mappings. If you need help, feel free to contact me.

How To Use It

After you've done the setup, the following screen snapshots show how to use the script. When you open iTunes, you will notice an AppleScript icon between the Window and Help pull-down menus. Select a playlist from the "Source" area on the left side of the screen. When you pull-down on the AppleScript icon, you should see the script (as you've named it) in the menu.

After you've started the script (by letting off the mouse button), it will prompt you to choose a name and output location.

As the script is running, if you enabled the option, then the shuffle button will blink on and off.

 

When the script is complete, it will prompt with a dialog which indicated how many tracks were written to the output file.

And that's it! Now you might have to move the file into wherever your AudioTron searches for files. Next, tell your AudioTron to search for new files (via the web interface or the options button on the unit), then the new playlist should be available. If you're updating an existing playlist, you don't need to tell the AudioTron to search for new files...the next time you select this playlist, it will see the new contents.

Changing Settings

To change the settings due to a change in the network configuration, name change, etc. be sure to quit iTunes, then launch Export Playlist to M3U from the Finder. The following dialog will be displayed.

You may either choose to go through the wizard setup as described above, read the settings from a file, or display the current settings. If you choose to display the current settings, you will see a dialog with your settings similar to the following.

At this point you can simply quit or go through the wizard setup, or read settings from a file.

When you choose to read settings from a file, the following dialog will be displayed.

Choose a previously saved settings file, then click Open. After the file has been read, the following dialog will appear.

Those are all the ways to setup the mappings. If you need something more specialized, you may edit your own settings file by hand, or modify the script directly according to your needs.

Disclaimer

This script was developed using Mac OS X 10.2.3 and iTunes 3. I currently use it with Mac OS X 10.2.5 and iTunes 4. Of course, it may work in other environments...your mileage may vary. This script may be freely copied, modified and used as you see fit. This script comes with no guarantee or waranty whatsoever, so use it at your own risk (that's my standard disclaimer ;-).


This page was last updated on: Tue Apr 29 07:38:23 PDT 2003