views:

579

answers:

4

On Mac OS X, you can create a zip archive from the Finder by selecting some files and selecting "Compress" from the contextual menu or the File menu. Unfortunately, the resulting file is not identical to the archive created by the zip command (with the default options).

This distinction matters to at least one service operated by Apple, which fails to accept archives created with the zip command. Having to create archives manually is preventing me from fully automating my release build process.

How can I create a zip archive in the correct format within a shell script?

A: 

The clue's in the tag 'automation'.

Create an action in Automator.app that uses the 'Create Archive' action, invoke it from the command-line (see 'automator').

Interesting, I had no idea there was an automator shell command! But won't that make the little robot bounce up and down in my Dock every time I make a build?
benzado
So long as the action doesn't prompt for input, it should run unattended and with no bouncing robot of any kind.
Automator, including the command line tool, requires access to the window manager, and therefore can only be launched as part of a console session, not unattended.
millenomi
Worked ok in a shell script for me; what sort of problem would you expect?
+3  A: 

Use the ditto command-line tool as follows:

ditto -ck --rsrc --sequesterRsrc folder file.zip

See the ditto man page for more.

millenomi
With this, I still can't produce a .zip which has the same signature as Finder's compress function. However, I didn't know about ditto :D
freespace
Likewise, but it looks much closer than the output of 'zip'. Differences could be down to timestamps or similar.
Remember to add in --keepParent. If you read the man page (man ditto):The command: ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip will create a PKZip archive similarly to the Finder's Compress functionality.
Harry
+2  A: 

I have a ruby script that makes iPhone App Store builds for me, but the zips it was generating wouldn't get accepted by iTunes Connect. They were accepted if I used Finder's "Compress."

millenomi's answer came close for me, but this command is what ended up working. iTunes Connect accepted my build, and the app got approved and can be downloaded no problem, so it's tested.

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

Jared Egan
A: 

Any hints how to create a windows zip file from the ditto utility?

This command creates a zip with resource forks included. ex. "file.txt" will also generate ".file.txt" ditto -ck --rsrc --sequesterRsrc folder file.zip

This command creates everything but it also includes a _MACOSX folder: ditto -c -k -X --rsrc some_folder some_folder.zip

I cannot find the magical set of arguments to create a clean windows zip from mac os X.

narco
You should post a new question, rather than posting your question as an answer to this one. Because it's not an answer and nobody will find it here.
benzado