10.6: Create a new Service to 'tar' directories or files

Apr 08, '10 07:30:02AM

Contributed by: TonyT

Snow Leopard only hintWhen I need a container of files, or of a directory that is already compressed (i.e. jpg images), there is no need to 'compress' into a zip file, so the following OS X Service will replicate the Compress 'right-click' with tar:

  1. Open Automator and select Service from the main screen.
  2. Set the 'Service Receives Selected' pop-up menu to Files or Folders, and set the 'in' pop-up to Finder.
  3. Drag Utilities » Run Shell Script into the workflow area.
  4. Set the 'Pass input' pop-up to as arguments.
  5. Delete all of the sample code, and replace with this:
    Tarfile="$1.tar"
    count=1
    cd "${@%/*}"
    if [ $# -eq 1 ]; then 
      while [ -e "$Tarfile" ]
      do
        let count++
        Tarfile="$1 $count.tar"
      done
    else 
      Tarfile="Archive.tar"
      while [ -e "$Tarfile" ]
      do
        let count++
        Tarfile="Archive $count.tar"
      done
    fi
    /usr/bin/tar -chf "$Tarfile" "${@##*/}"
  6. Select File » Save and name your new Service (Package into Tar or whatever).
  7. Quit Automator and try your Service in the Finder with a selection of files.
[robg adds: This worked as described for me.]

Comments (5)


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