Quickly create .tar files in Finder

You probably know that you can quickly create a compressed file archive in Finder by selecting the files to be compressed, Control-clicking, and selecting Compress number Items from the contextual menu. What if you want to package a bunch of files together in one file, but don’t necessarily need to compress them? MacOSXHints.com reader TonyT has a solution:

Open Automator and select Service from the main screen. Set the ‘Service Receives Selected’ pop-up menu to Files or Folders, and set the ‘in’ pop-up to Finder. Drag Run Shell Script from the Utilities section of the actions library into the workflow area. Set Pass Input to As Arguments. Replace the sample code in the input area with this:

 cd "${@%/*}"
 if [ $# -eq 1 ]; then 
   while [ -e "$Tarfile" ]
      let count++
      Tarfile="$1 $count.tar"
   while [ -e "$Tarfile" ]
     let count++
     Tarfile="Archive $count.tar"
 /usr/bin/tar -chf "$Tarfile" "${@##*/}"

Select File -> Save and name your new Service (Package into Tar or whatever you want). Quit Automator, select some files in Finder, then Control-click (or right-click) and select your new service from the Services submenu.

The service will create the .tar file in whatever folder the selected files were in. You can, of course, rename and move it however and wherever you wish.

To comment on this article and other Macworld content, visit our Facebook page or our Twitter feed.
Shop Tech Products at Amazon
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.