A script to sync podcasts to a USB drive or SD card

Mar 24, '05 09:43:00AM

Contributed by: tmcintir

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.

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=200503231802515