I want to add song files to iTunes via the command line.

    open -a iTunes -g song.mp3

does exactly this. - However it starts playing the song, too. Any way to avoid this?

up vote 11 down vote accepted

You can use the "Automatically Add to iTunes" folder for that (see PH19617):

cp song.mp3 ~/"Music/iTunes/iTunes Media/Automatically Add to iTunes/"

If iTunes is running, anything you copy into this folder will be imported into iTunes automatically (and deleted from the folder afterwards).

Please note:

  • The folder name might be language specific, so check the name on your system first.
  • Depending on when iTunes was installed, the media folder may be called either iTunes Media or Tunes Music
  • Works a treat. Thanks! – halloleo Apr 20 '13 at 2:19
  • 1
    You should use mv instead of cp so that the file is added and you are not left with a duplicate song file outside of your iTunes library. – CyberSkull Apr 28 '13 at 23:11
  • 1
    Not only does the "Automatically add to iTunes" folder simply not work in many instances, it doesn't work for a distributed library. – Marshall Eubanks Jun 4 '14 at 15:31
  • 1
    Support for distributed libraries isn't part of the question here. But you are correct: if you distribute your iTunes library across several disks neither "Add to iTunes" nor dragging media files into the iTunes window will import in a useable way. – nohillside Jun 4 '14 at 17:23

You can use applescript to do so and there's much more to explore. (add music to special playlist, etc.)

for example, you need to add file /User/username/myMusic/my.mp3 to lib, create a script file named add.scpt

tell application "iTunes"
    add alias ((path to home folder as string) & "myMusic:my.mp3") 
end tell

run command:

osascript add.scpt

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.