diff --git a/README.md b/README.md index 2e9e4a5..bdf40a9 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,18 @@ iTunes Sync Android iTunes Sync Android is a command line utility to sync one of your iTunes playlists to any Android cell phone mounted as a disk volume on your Mac. ## Requisites -* [MacRuby]() \ No newline at end of file +* [MacRuby](http://www.macruby.org/) 0.9 or later +* Mac OS X 10.6 or later +* iTunes + +## Usage + +```bash +macruby itunes_sync_android.rb "/Volumnes/NO NAME/Music" "Nexus One Sync" +``` + +For example, if you want to copy your song files from your iTunes playlist **Nexus One Sync** to your Android phone mounted via USB on **/Volumes/NO NAME/Music** + +```bash +macruby itunes_sync_android.rb "/Volumnes/NO NAME/Music" "Nexus One Sync" +``` \ No newline at end of file diff --git a/itunes_sync_android.rb b/itunes_sync_android.rb index f4c9611..033ba27 100644 --- a/itunes_sync_android.rb +++ b/itunes_sync_android.rb @@ -3,26 +3,39 @@ # http://stackoverflow.com/questions/1968794/create-itunes-playlist-with-scripting-bridge require 'fileutils' - framework 'Foundation' framework 'ScriptingBridge' -destination_path = ARGV[0] +SOURCE = "Library" +DEFAULT_PLAYLIST = "Nexus One Sync" + +if ARGV[0].nil? + destination_path = "#{Dir.home}/Desktop/#{itunes_playlist}-#{Time.now.strftime("%Y%m%d%H%M%S")}" + FileUtils.mkdir_p destination_path +else + destination_path = ARGV[0] +end +itunes_playlist = ARGV[1] || DEFAULT_PLAYLIST itunes = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") # playlist = itunes.sources["Library"].userPlaylists["*Nexus One Sync"] +puts "Copying files from playlist \"#{itunes_playlist}\" to path: #{destination_path}" + itunes.sources.each do |source| library = source - if source.name == "Library" + if source.name == SOURCE library.userPlaylists.each do |play_list| - if play_list.name == "*Nexus One Sync" + if play_list.name == itunes_playlist play_list.fileTracks.each do |fileTrack| path = fileTrack.location.path.to_s filename = fileTrack.location.lastPathComponent.to_s FileUtils.cp(path, "#{destination_path}/#{filename}") + puts "Song file... #{filename}" end end end end end + +puts "Done!" \ No newline at end of file