MacOS – Copy contents of a smart folder to a new folder in Mountain Lion

bashfilefoldersmacossmart-folders

I admit that my music collection is a royal mess. This is the result of merging many sources of music (external drive, old iPod sync, iTunes purchases, etc) into my iTunes account. iTunes Match has done a pretty good job of cleaning it up visually as I look at it in iTunes.

What I want to do is create a backup copy of all my music no matter where it lives (external HD, etc.) to one location and hopefully eliminate duplicates in the process.

More specifically, I setup a smart folder to find all of kind:music with a bitrate over 44kbps. This results in over 20,000 music files at around 485 GB. I now want to copy all this content to my external drive to ensure I have a backup of all these audio files.

I tried a simple select all and drag to copy, but that didn't seem to work. After a few days of Finder "not responding", I killed the process. Some zero-byte files were created on the external drive, but no sign of progress after the first few minutes.

I'm wondering if there is a Terminal command that could reference the contents of a smart folder and copy or some other creative way to get this done.

I really don't want to mess with iTunes, I just want to copy all music files to the external HD. Bash script maybe?

Best Answer

You could use mdfind in a shell script to simulate your smart folder's settings (mdfind is how you use Spotlight from the command line). Use kMDItemKind to specify the kind and kMDItemAudioBitRate for the bitrate.

Then you can use that list of files and copy them to your external drive.

Something like this script below. (scp copies files to a server; use cp to copy to a drive. Or, if you want to get fancy, rsync is generally better for incremental backups.)

#!/bin/bash

for FILE in $(mdfind 'kMDItemAudioBitRate >= "44000"')
do
    scp $FILE myname@myserver:~/music-backup
done