34

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?

EDIT: Since writing this question long ago, I've figured out that the key difference between ditto and zip is how they handle symbolic links: because the code signature inside an app bundle contains a symlink, it needs to be preserved as a link and not stored as a regular file. ditto does this by default, but zip does not (option -y is required).

2
  • Which version of OS X are you running?
    – freespace
    Sep 20, 2008 at 11:19
  • Try this - create an archive using finder with a single file in it, doesn't matter what it is. Now add a file to it using command line zip. This should only modify the zip master directory, and leave whatever apple magic alone - might be enough to get pass the detectors :P
    – freespace
    Sep 20, 2008 at 11:42

4 Answers 4

20

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" function.

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
18

Use the ditto command-line tool as follows:

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

See the ditto man page for more.

4
  • 1
    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
    Sep 20, 2008 at 11:33
  • Likewise, but it looks much closer than the output of 'zip'. Differences could be down to timestamps or similar.
    – Mike F
    Sep 20, 2008 at 12:19
  • 12
    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
    Nov 20, 2009 at 1:29
  • link is dead...
    – NooberMan
    Jan 10 at 7:28
11

man ditto states:

 The command:
       ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip
 will create a PKZip archive similarly to the Finder's Compress functionality.

notice --keepParent

1

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').

4
  • 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
    Sep 20, 2008 at 11:22
  • So long as the action doesn't prompt for input, it should run unattended and with no bouncing robot of any kind.
    – Mike F
    Sep 20, 2008 at 11:24
  • 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
    Sep 20, 2008 at 11:29
  • Worked ok in a shell script for me; what sort of problem would you expect?
    – Mike F
    Sep 20, 2008 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.