How To Add Recent Files To iTunes from Command-line

Scanning for MP3s and adding them to iTunes library

By Takeshi Kanemoto
On Nov. 20, 2011, 1:14 a.m.

The following scans recursively for all MP3 files modified in the last 30 days and add them to iTunes library.

find . -type f -name '*.mp3' -mtime -30 -print0 | xargs -t -0 open -a iTunes osascript -e 'tell application "iTunes" to pause'
Obviously, you should set/change $MEDIA_DIR to the directory you want to scan from. Opening the files should add them to the iTunes library, but it also makes iTunes play the files, so the last line is there to make iTunes pause as soon as the files are added.

About the author

Takeshi Kanemoto

I'm a software engineer based in Cambridge, UK.