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.

Shop ▾
arrow up Amazon Shop buttons are programmatically attached to all reviews, regardless of products' final review scores. Our parent company, IDG, receives advertisement revenue for shopping activity generated by the links. Because the buttons are attached programmatically, they should not be interpreted as editorial endorsements.

Subscribe to the Best of Macworld Newsletter