Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to sync podcasts to a USB drive or SD card Apps
Here's a shell script to sync your Podcasts to your USB drive, SD card, or non-iTunes-compatible MP3 player. Somebody could probably doll it up into an AppleScript which automatically ran on mount; I just type ./podcast.sh from the Terminal. The script copies all my new Podcasts and then unmounts the drive.

Here's the podsync.sh script -- I put mine in ~/Podsync:
#!/bin/sh

cd  ~/Podsync

ls ~/Music/Podcast/*.mp3 > current.tmp

echo ""
echo "Podsync"
echo "---"

i=1
scount=0
ccount=0
while [ 1 ]
do
  entry=`awk '(NR=='$i') {printf $1}' ./current.tmp`
  if test "$entry" = ""
  then
    break
  fi
  echo "$i: $entry"

  check=`grep $entry ./copied.tmp`
  if test "$check" = ""
  then
    cp $entry /Volumes/SDCARD/AUDIO/.
    echo "COPIED"
    echo $entry >> copied.tmp
    ccount=`expr $ccount + 1`
  else
    scount=`expr $scount + 1`
    echo "SKIPPED"
  fi

  i=`expr $i + 1`
done

echo "---"
echo "$ccount items copied, $scount items skipped."
hdiutil unmount /Volumes/SDCARD/
echo ""
For those who don't know, ~ is your home directory (i.e. /Users/YOURUSERNAME). Change ~/Music/Podcast to the name of the folder where you keep your podcasts and /Volumes/SDCARD to the /Volumes/USB_mount_location. Also, don't forget to type chmod +x podsync.sh before you use your script for the first time, so it will be executable.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[7,453 views]  

A script to sync podcasts to a USB drive or SD card | 4 comments | Create New Account
Click here to return to the 'A script to sync podcasts to a USB drive or SD card' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to sync podcasts to a USB drive or SD card
Authored by: fungus on Mar 24, '05 05:42:32PM

Not a bad script, but I would prefer to use rsync. rsync will compare the directories and transfer any missing/changed files. It will also recurse through all subdirectories so you can organize your podcasts.

rsync -av --delete ~/Music/Podcasts/ /Volumes/SDCARD/audio/

[ Reply to This | # ]
A script to sync podcasts to a USB drive or SD card
Authored by: tmcintir on Mar 24, '05 06:13:30PM

There are a couple of important things that the 'rsync' method doesn't do:

I want to be able to delete files after I've listened to them on my SD Card, without having the 'sync' command reintroduce them. This allows me to keep track of which podcasts I have listened to. The script keeps a history of what has been copied so you don't get files you've alreadty listened to and discarded.

(maybe there are diffferent command-line options for rsync that would do this, which would be great, but I think you still need a script which keeps a history)

I was considering making the script actually delete items from the ~/Music/Podcast/ folder if they have been deleted from the SD Card, but decided not to for now as an archive. (You can't do this with the --delete option for rsync because it would delete new podcasts in addition to discarded ones).

---
Tim McIntire
McIntire Computing Group
www.mcintireCG.com



[ Reply to This | # ]
A script to sync podcasts to a USB drive or SD card
Authored by: amacaulay on Mar 30, '05 07:43:34AM
I may be missing something, but it looks as though your requirement is what I'd describe as a "merge" rather than a "sync." You want new podcasts to make it onto the device, but you don't want the deletion of podcasts from your source directory to be reflected in the destination directory. You also don't want changes to the destination directory to trigger any changes to the source directory. The quick tests I've done suggest the simple command line
cp -Rn source-dir dest-dir
would do this. The R flag makes the command recurse, the n flag prevents overwriting of existing files in the destination. Andy.

[ Reply to This | # ]
Oops
Authored by: amacaulay on Mar 30, '05 07:45:38AM

Ah - the cp method would resurrect files you deleted from your device. Sorry.



[ Reply to This | # ]