Search code examples
objective-ccocoacompressionapplescriptcore-services

use Archive Utility.app from command line (or with applescript)


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.


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.