Question

I would like to use Archive Utility.app in an app I'm writing to compress one or more files.

Doing (from the command line):

/System/Library/CoreServices/Archive\ Utility.app/Contents/MacOS/Archive\ Utility file_to_zip

Does work but it creates a cpgz file, I could live with that (even though .zip would be better) but the main problem is that I am not able to compress 2 files into 1 archive:

/System/Library/CoreServices/Archive\ Utility.app/Contents/MacOS/Archive\ Utility ~/foo/a.txt ~/bar/b.txt

The above command will create 2 archives (~/foo/a.txt.cpgz and ~/bar/b.txt.cpgz).

I cannot get this to do what I want either:

open -a /System/Library/CoreServices/Archive\ Utility.app --args xxxx

I'd rather not use the zip command because the files that are to be compressed are rather large so it would be neat to have the built in progress bar.

Or, could I use Archive Utility programmatically?

Thanks.

Was it helpful?

Solution

Archive Utility.app isn't scriptable.

The -dd/--display-dots option will cause the command-line zip utility to displays progress dots when compressing. You could parse the output of zip for your progress bar. zip will also display dots if it takes more than five seconds to scan and open files.

Better would be to integrate a compression library, such as zlib or libbzip2. Both of those let you compress a portion of the data at a time. You'll need to handle progress bar updates, which you can do after compressing each block of data.

OTHER TIPS

Archive Utility.app uses the following to create its zip archives:

ditto -c -k --sequesterRsrc --keepParent Product.app Product.app.zip

How about Automator? The "Create Archive" action would work.

I have used Archive Utility to decompress files from Applescripts:

tell application "Archive Utility" to open filePath

However, this only tells Archive Utility to start decompressing. It will complete in its own time and the applescript will continue to execute without waiting for the decompression to finish. Archive Utility will not tell the applescript when it is done.

You can use the above line if Archive Utility is already running. It will add the new file to its queue and decompress when ready.

Also, Archive Utility's preferences will control how it accomplishes the goal. For example: it might decompress to a different folder or delete the original. You can run it as a program and change the preferences if that helps.

I have not used this to get Archive Utility to compress files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top