Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Easy iTunes playlist syncing for Tesla USB flash drive

This site may earn commission on affiliate links.
Highlights of the script:
- This script is for anyone that uses playlists for listening- not genre, album, artist, etc. as there are multiple copies of a song on the flash drive.
- Syncs (selectively) multiple playlists from iTunes to a drive/folder of your choice (including USB flash drive)
- Adds and deletes files automatically to reflect your current iTunes playlist setup in iTunes playlist folder Tesla (can be changed in the script)
- Changes the song genre to reflect the iTunes playlist for the copied file. The iTunes file retains it's current genre setting
- Play your playlist by selecting Genre in the Media Player of the Tesla
- Automatically converts Apple Lossless files to flac (using XLD's command line interface)

Details:
I've assembled an AppleScript that will sync a folder of iTunes playlists to a USB flash drive or a folder on your Mac. (No windows version :( as I've used AppleScript for this.) You define a folder in iTunes (the default is Tesla) and add any playlists to it that you would like to sync. The script will copy all of the songs to your destination drive/folder and rename the genre of the song to the playlist. Using the media player in the Tesla, you can then select genre which will reflect your playlists in iTunes. (The genre of the iTunes song is temporarily changed when the file is copied but then changed back to the original genre.) If you have Apple Lossless files, you'll need to install both XLD and the command line script xld (included with the package) and the script will automatically convert the files to the flac format, playable in the Tesla. (You may need to make the xld script executable to work.)

Instructions:

1- Copy the script to the location of your choice on your Mac.
2- Install XLD on your Mac and install the command line tool (in CLI) from http://sourceforge.net/projects/xld/files/latest/download
3- Install the xld CLI in your applications folder. You made need to make it executable using terminal and chmod. Open terminal, type cd /Applications, type sudo chmod 755 xld. Enter your system password and press enter.
4- Create a playlist folder in iTunes named Tesla and drag any playlists you'd like to sync to this folder. (You can change the default folder in the script if you'd like.)
5- Run the script (link below).
6- Choose your destination disk/folder.
7- Wait. If you have a lot of songs, it can take a long time. Hours. Particularly when copying to a USB flash drive.
8- Caution: the script does not check for adequate disk space. And since it makes multiple copies of the same file per playlist, it can use quite a bit of disk space. I'm not certain what would happen if a flash disk ran out of space.

Notes:
1- I'd initially choose a small playlist to test the setup. And sync to a folder on the desktop for testing. Better yet, make a copy of your iTunes folder, open the backup (using the Option key when clicking on iTunes and then select the backup). Note you'll have to change it back once done testing.
2- Although the initial sync can take a while, future syncs will go much more quickly when only small changes have been made. The script will add and delete files to your destination based on your current playlists in the "Tesla" folder in iTunes.
3- Your will end up with duplicate files on the destination drive/folder. Each song is copied from the playlist and the genre named to the playlist. This means that if a song appears in 5 synced playlists you'll have 5 copies of the song.
4- If you initially sync to a folder on your hard disk, you can copy the folder to the USB drive. Next time, sync to the flash drive directly. It's a little less error prone due to timeouts or slow USB drives.
5- The progress meter and counts are sometimes a bit wonky. They may or may not represent what is actually happening exactly... just sorta.
6- The script makes a temp playlist called ZZ-Temp (get it?) and copies all of the playlist files to it. This playlist is not deleted at script end so that you can use it as a proxy to see how many files there are. This can be compared to the destination folder. The playlist folder is deleted on the next run of the script and then re-created with the designated playlists in the Tesla folder.
7- I've had timeout errors that I can't diagnose (maybe Time Machine locking files, other apps, etc.). If the final dialogue box reports errors or their is a discrepancy between the ZZ-Temp playlist and the number of files in your destination folder, just run the script again. If it the issue is a timeout, usually second times a charm!
8- The only risk to your iTunes library is that the genre is changed momentarily when copying the file to the destination folder. If the script were to crash, there is a possibility that the iTunes song would be left with the playlist as genre vs. your original designation. In my month of use, I've seen this occasionally but now trap most errors when copying the songs.
9- You can save the script as an application bundle, which will allow it to run directly without opening up the script editor.

Please make certain that you have a backup of your iTunes folder when you first start using this script. I have tested it on my Mac and laptop which are running Yosemite and the latest iTunes 12.1.0.50 as of March 5, 2015. The progress bar may break in earlier versions of OS X... not certain as I can't test but it is a new feature.

So, this script works for me but note that I've cobbled it together and am *not* a programmer per se. There will be bugs and issues but in the end, this makes syncing a USB flash drive almost as easy as syncing an iPod. Which is nice...

Please provide any feedback or if there are any AppleScript gurus out there, suggestions on how to improve it.

Finally, many thanks and a shout out to Doug's iTunes Scripts (Doug's AppleScripts for iTunes - dougscripts.com) for both the inspiration, samples, snippets and general guidance for using AppleScript with iTunes. Highly recommended!

Download script from:
https://www.dropbox.com/s/pea6ympevcjmawm/Tesla iTunes Playlist Sync v1.scpt?dl=0
 
Last edited:
I'm also working on a sync script that will copy all files from selected playlists to a USB drive but preserve the genre and eliminate any duplicates...

It will also convert Apple Lossless to flac.

Let me know if you're interested. I'd like to flush out any errors in the above script as the new one relies heavily on the code in the original.
 
XLD is only used for Apple Lossless files as they won't play in the Tesla. XLD will convert them to flac with no loss in quality. All other song files are copied in their native format as the Tesla supports all iTunes formats except Apple Lossless.
Right. I just didn't want to be re-encoding lossy formats. Looks like a neat tool, I'm going to give it a shot.
 
Wow! I can't wait to try this out!

Thank you!!!

Alan

You're welcome! Let me know if you have any issues or questions... It works well on my system and setup but that's a very limited user test! :)

Again, I'd suggest using a small playlist and consider copying your iTunes library as a test bed.

- - - Updated - - -

Right. I just didn't want to be re-encoding lossy formats. Looks like a neat tool, I'm going to give it a shot.

Agreed. The Tesla supports AIFF files (as does iTunes) but they are twice as large as either flac or Apple Lossless. The script will copy the AIFF files without modification, just like mp4, aac, mp3, etc.

You can look at the script and see the logic. I tried to document the various functions...

Please let me know how it goes!
 
Just had a report that the script will only run with Yosemite... apparently the progress bar function limits it to Yosemite only. I'll post an updated script without the progress bar later this week.

As an aside, is there a way to edit my initial post to show updates and revisions? I don't see an option for it on the post...
 
is there a way to edit my initial post to show updates and revisions? I don't see an option for it on the post...

"Report" your last post (or this one) requesting the forum moderators to "make a wiki" out of your second (I think it's limited to that) post... makes it ever-update-able.
Thanks for the script work, can't wait to try it out once I cram a pile of CDs into iTunes in lossless!

Rick
 
Awesome idea, thank you for sharing this!

I am completely inept when it comes to programming.
I have the script, and installed XLD and then moved the CLI folder to the applications folder. It seems to run.
I created a Playlist titled Tesla and copied a half dozen songs into it.
Ran the script, selected a test folder I had created on my desktop.
I am running Yosemite 10.10.2


When running the script though, I get:

Can’t get «class cFoP» "Tesla" of application "iTunes".
iTunes got an error: Can’t get folder playlist "Tesla". (-1728)

Is it possible this is because my iTunes library is on an external hard drive?
 
Awesome idea, thank you for sharing this!

I am completely inept when it comes to programming.
I have the script, and installed XLD and then moved the CLI folder to the applications folder. It seems to run.
I created a Playlist titled Tesla and copied a half dozen songs into it.
Ran the script, selected a test folder I had created on my desktop.
I am running Yosemite 10.10.2


When running the script though, I get:

Can’t get «class cFoP» "Tesla" of application "iTunes".
iTunes got an error: Can’t get folder playlist "Tesla". (-1728)

Is it possible this is because my iTunes library is on an external hard drive?

You're almost there... First, unless you have Apple Lossless files in your iTunes library, you don't need XLD and skip to step 2.

1) If you do, you'll need to copy the xld (all lower case) script from the CLI folder to your Applications folder. (You also need to make it executable using terminal and chmod. Open terminal, type cd /Applications, type sudo chmod 755 xld. Enter your system password and press enter.)

My initial instructions are confusing... CLI stands for command line interface but it is also the name of the folder that has the script.

2) Create a Playlist Folder in iTunes (Under File->New->Playlist Folder) named Tesla (not a playlist). Next, add an existing playlist or two (or make a new one) to the folder. It should look like this the picture below (but with your playlists in it!).

It's step #2 that's causing the script to crash. I'll look into adding a little error handling there to provide a more gentle crash.

The script will copy your playlists to your destination and rename the genre's name to match your playlists. On the Tesla, insert your USB flash drive and then go to Genre and you'll see a listing of your playlists. Select one to play. Works well with the new shuffle function.

Post back here if you need more help. And thanks for checking it out!

Screen Shot 2015-03-10 at 5.49.27 PM.png
 
Last edited:
DOH!
Your instructions were just fine, I just never used a Playlist Folder before.
Where my eyes saw "playlist folder" my brain registered "playlist".

It works wonderfully, thank you for creating, sharing, and patiently explaining it (twice)!
 
For anyone not on Yosemite, I've gone through and commented out the "progress bar" script as it works only in Yosemite. Link is below...

Note that you won't have any indication that something is running other than the script editor will say "running" in the bottom of the screen. As I've mentioned before, it can take hours to do an initial sync and copy. Best to start with a clean USB flash drive. A faster machine and USB 3.0 USB drive will make a huge difference in the initial sync. But be patient. If if there are timeout errors, syncing again will take less time (moving fewer songs to the drive or folder). You can always select a folder on your computer (or add one) and then sync with the folder. After the sync, copy the folder to your USB flash drive...

I use a USB 3 flash drive and have a relatively new iMac. I sync almost 170 GB of songs and it takes less than five minutes to sync the entire flash drive (after the initial sync)... About as long as my iPhone takes...

Here's the link for anyone using Maverick's or less (OS X version 10.9 or lower). Let me know if you have any issues.

Dropbox - Tesla iTunes Playlist Sync v1.1 - OS X 10.9 (Mavericks) or less.scpt
 
Wasn't sure whether to make a new thread, or add to here. Ironically this thread got started soon after I had just completed a basic command line version of a utility to sync my iTunes library to a USB drive for the car. While it worked, I wanted to make something a little more accessible, with my normal use case being something to the effect of, "start app, push 'do it' button. Go have a drink."

So I did. Make the app that is - though there may have been drinks too.

1fd1d3dc-cc38-11e4-9e9d-1111af6e7c14.jpg


First off, at the moment it is a Mac only app. Sorry Windows and Linux folks. OS X is my usual system and it started as a personal utility, not as something aimed at what would hit the most potential users. I'll see what I can do about that based on time and interest, but want to get it more complete anyway before adding other platforms.

MajorLance's version still does things mine doesn't. I don't do any playlist level syncing yet. My focus was on scanning the whole library and copying over just any new files I'd added to the library since last time, while also doing the whole Apple Lossless to Flac routine automatically and transparently.

You can find it here (goes to github): Tesla Tunes.
Off the download latest link, there's a zipped up TeslaTunes.app file - you don't have to be a developer or anything to use it.

It doesn't, or at least shouldn't, require any extra downloads to run - just unzip it and throw the app wherever you want (you know, like Applications - but it's not picky).

It's basic, but I've found it useful. Should any of you also want to try it out, feel free. Leave feedback at the site, or here (in a new thread probably?) if you wish. I'm interested in how many people find individual playlists to be the best unit of transfer vs. how many just want the whole enchilada dealt with as easily as possible.

I appreciate MajorLance's work it looks genuinely useful and it was smart to target the functionality towards playlists. Aside from that, it prompted me to go ahead and get this out of the stages of works for me and into a (slightly) more useful for others state. I'm not sure which would be better or more useful to people in general, but it's awesome to have any choices at all vs. the more manual routes many of us were taking before.