Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 929
LG01 Avatar asked Oct 13 '11 00:10

LG01


People also ask

How to archive a file in mac Terminal?

Create a compressed tar archive In the Terminal app on your Mac, enter the tar command, then press Return. The z flag indicates that the archive is being compressed, as well as being combined into one file. You'll usually use this option, but you aren't required to.

What is MacOS archive utility?

Apple's macOS uses Archive Utility, a small app hidden away in an obscure folder and used to create and decompress . zip files. The Archive Utility app has some options that may make working with archives easier.


2 Answers

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

ditto -c -k --sequesterRsrc --keepParent Product.app Product.app.zip
like image 104
Padraig Avatar answered Oct 20 '22 13:10

Padraig


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.

like image 29
outis Avatar answered Oct 20 '22 13:10

outis