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

10.4: An Automator plug-in to tar and gzip in the Finder Desktop
Tiger only hintI've written an Automator workflow that can be used as a Finder plug-in to tar and gzip any selected files or folders.

First, download the action. After it's downloaded, do this to get it working:
  1. Double click the tgz folder.dmg disk image to mount it.
  2. From your home folder, make the following hierarchy of folders if it doesn't already exist: /Library -> Workflows -> Applications -> Finder
  3. Drag the tgz.workflow workflow from the disk image into the Finder folder you just created.
Now you can select files or folders in the Finder, control- or right-click, go to the Automator sub-menu, and select tgz to compress them.

[robg adds: I've mirrored the action in case the above download link goes away some day. Since 10.4 now retains resource fork info with all the command line utilities, this should be safe to use on any files. I tested it, and was able to compress (and the decompress) a set of files without any troubles. Note that you can also put the workflow in your user's Library folder, following the same structure as above, instead of the top-level Library -- this would install it only for your user instead of all users on the system.]
    •    
  • Currently 2.80 / 5
  You rated: 5 / 5 (5 votes cast)
 
[20,078 views]  

10.4: An Automator plug-in to tar and gzip in the Finder | 21 comments | Create New Account
Click here to return to the '10.4: An Automator plug-in to tar and gzip in the Finder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: reh on Aug 05, '05 10:57:29AM

If you don't like seeing just "tgz" in your automater menu, then change the name of the file from "tgz.workflow" to something like "Create TGZ Archive.workflow"



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: SimonDorfman.com on Aug 05, '05 11:22:08AM

I wonder if there's an easy way to exclude .DS_STORE files from the tar gzips. Ideas anyone?



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: owsla on Aug 05, '05 11:46:10AM

In the Automator action, try changing the line:

tar czf "$file.tgz" "$file"

to:

tar czf --exclude ".DS_STORE" "$file.tgz" "$file"



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: jwbales on Aug 05, '05 11:49:14AM
Open the workflow in Automator and change the script. Change:
tar czf "$file.tgz" "$file"
To:
tar --exclude=".DS_Store" -czf "$file.tgz" "$file"


[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: SimonDorfman.com on Aug 05, '05 04:32:34PM
Thanks for your help with this. I made one to make zip archives that exclude .DS_Store files too. Here's the code:

for f in "$@"
do
	path=`dirname "$f"`
	file=`basename "$f"`
	cd "$path"
	zip -r "$file.zip" "$file" -x \*.DS_Store
done
I just replaced the line
tar --exclude=".DS_Store" -czf "$file.tgz" "$file"
with this one:
zip -r "$file.zip" "$file" -x \*.DS_Store
This actually excludes any file ending with .DS_Store. I couldn't figure out the syntax to specify just one file. Reading man pages is still new to me. But how often do you have a file called my_important_document.DS_Store ? Right, me neither, so this script works fine then :-)

[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: dan55304 on Aug 05, '05 12:16:19PM

I've tried all variations here. I get the error "tcsh: illegal variable name" with all of them. Any ideas?



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: rv8 on Aug 05, '05 01:18:03PM

I had to change the shell to /bin/sh to get it to work. This is in the drop-down menu in the second action of the Workflow in Automator.

---
Kevin Horton



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: sporkstorms on Aug 05, '05 07:35:51PM

It should have been /bin/bash as the shell (which is what I made it when I created the workflow).
Automator must revert it to the user's default shell or something, which is just plain absurd! Thanks for bringing this up, and I'll going to figure out exactly what's going on here.

But yes, the immediate solution is to simply double click the "tgz.workflow" file, and pick /bin/bash or /bin/sh from the drop-down in box #2 of the workflow.



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: porkchop_d_clown on Aug 06, '05 08:50:57AM

Does it work like shell scripts? Would adding

#!/bin/bash

to the first line solve the problem?

---
Everyone loves a clown, but no one will lend him money!



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: YoGi on Aug 07, '05 04:45:28AM

Yes, adding

#!/bin/sh

solves the problem.



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: Mike A on Aug 05, '05 12:30:41PM
I've created a similar workflow that will create Disk Images in the same manner. Find it at: http://www.macupdate.com/info.php/id/18276

[ Reply to This | # ]
Warning: Workflow Attempts to Compress the Entire Filesystem
Authored by: forman on Aug 05, '05 02:01:12PM

I wanted to warn users that the default installation of this workflow on my system does a very bad thing. Specifically, the workflow attempts to create a gzipped tape archive (tgz) of my entire filesystem.

If this happens to you, open a terminal and run "top -ocpu -R -F -s 2 -n30". You'll see two processes one called "gzip" and the other "gtar". Find their process numbers and kill them ("kill [gzip PID] [gtar PID]"). You'll then need to delete the massive tgz file hiding in the root directory. It's called "/..tgz". You can delete it by typing "rm /..tgz".

If I find the cause and solution to this strange behavior, I'll post it.

Michael.



[ Reply to This | # ]
Warning: Workflow Attempts to Compress the Entire Filesystem
Authored by: forman on Aug 05, '05 02:16:37PM
As was stated above, I had to change the shell to "/bin/sh" to get it to work. I had tried that previously without success, although now I wonder if I saved or not. :)

Michael.

[ Reply to This | # ]
Warning: Workflow Attempts to Compress the Entire Filesystem
Authored by: anamexis on Aug 05, '05 06:32:28PM
You could also just do
killall gzip gtar
instead of the two commands.

[ Reply to This | # ]
Warning: Workflow Attempts to Compress the Entire Filesystem
Authored by: forman on Aug 06, '05 10:22:12PM

I rarely use "killall" as it will kill all processes with the matching procname running as the current user. Granted it's quicker and the probability of problem is small but the same thing can be said about "rm" without the "-i" flag (and I know everyone has "rm" aliased to "rm -i"). :)

Michael.



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: mayo2ca on Aug 05, '05 02:20:14PM

The only way I can get this to work is to change "get Specified Finder Items" to "Get Selected Finder Items" as well as somebody else mentioned above changing the tcsh shell to sh. (haven't tried putting #!/bin/tcsh as the first line, but that'll fix it if you run the script manually in shell).

Few warnings:
- dirname to an empty string ("") will return ., so if you don't have anything selected it will gzip your current directory
- if you have files with spaces in them, they will not be archived, as Finder does not enclose them in "" when passing them as arguments to the script, and the script uses space as separator, so a filename with space will actually become two filenames
- it will create archive per filename, not one archive with multiple files



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: jpryor68 on Aug 05, '05 04:00:19PM

Funny: when I open the workflow file in Automator, all I see is a single action: Get Specified Finder Items (with no items specified). It seems clear that would work better as Get Selected Finder Items. But MORE IMPORTANTLY, this is the only action in the workflow. There's no second action included. Consequently, the workflow is incapable of doing anything.

At first I just thought the poster had submitted a buggy workflow. But now from the comments it looks like other people ARE seeing a second action. Weird. Have I damaged my Automator set-up somehow? I can't imagine how, I hardly use it. Any ideas?

I'm using 10.4.1.



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: Arlo on Aug 05, '05 05:23:47PM

This workflow requires OS X 10.4.2, as the shell script action was updated.

---
www.automatorworld.com
"Better Living Through Macintosh Scripting"



[ Reply to This | # ]
tar vs. gzip vs. Archive?
Authored by: axelfoo on Aug 05, '05 04:20:06PM

When or why would you use gzip or tar instead of Archive? Do those tools achieve higher compression?
Thanks!



[ Reply to This | # ]
tar vs. gzip vs. Archive?
Authored by: Krazy on Aug 05, '05 10:31:37PM

Generally, I find I it best to use tar and gzip together. Tar to collect a whole group of files & directories into one archive, and gzip to compress the archive. Alternatively, you can use bzip2 to compress the tar'ed archive to make it even smaller.

Why prefer this over Apple's 'Archive' [which is a variant of zip], then?
Well most *nix boxes will have both tar and gzip available, but not zip.



[ Reply to This | # ]
10.4: An Automator plug-in to tar and gzip in the Finder
Authored by: GlowingApple on Aug 10, '05 11:58:33PM

I'm getting a workflow execution failed error. I tried running the script in Terminal with a single file as the argument and it works, but in Automator, with a single file or multiple files I get that error. I tried changing the shell from /bin/bash to /bin/sh, but that didn't solve the problem? Any ideas what might be going wrong or what I can change to help debug the problem?

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]