Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X 'compress' option vs command line zip (why do they produce different results?)

I noticed that the command line 'zip' tool and Mac OS X's 'Compress XXX' option (available via right click in finder) are giving different output files. Not only is the size of the file a few hundred bytes bigger but the content is significantly different as well.

How can I find out what command the Finder is using for compression?

like image 607
Locksleyu Avatar asked May 24 '12 13:05

Locksleyu


People also ask

What does compress folder do on Mac?

Compressed files take up less disk space than uncompressed files, so compressing is useful for making backup copies of your data or for sending information over the internet.

How do I highly compress files on a Mac?

Compress a file or folder: Control-click it or tap it using two fingers, then choose Compress from the shortcut menu. If you compress a single item, the compressed file has the name of the original item with the . zip extension. If you compress multiple items at once, the compressed file is called Archive.

Why can't I open zip file on Mac?

You can use the Mac search at the top right and start typing Terminal. It will appear, click on it to open the program. Type “unzip” and a space, then drag/drop the zip file into the Terminal window. Press Enter and the zip file will be unzipped, storing all files on your computer.


2 Answers

The answer is in man ditto:

 The command:
       ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip
 will create a PKZip archive similarly to the Finder's Compress function-
 ality.
like image 97
Mark Adler Avatar answered Oct 22 '22 01:10

Mark Adler


Take a look at An AppleScript to compress a Finder selection article.

try
    tell application "Finder"
        set theSelection to the selection
        set selectionCount to count of theSelection
        if selectionCount is greater than 1 then
            error "Please select only one Finder item before running this script."
        else if selectionCount is less than 1 then
            error "Please select one Finder item before running this script."
        else
            set theItem to (item 1 of theSelection) as alias
            set destFolder to (container of theItem) as alias
            set itemName to name of theItem
        end if
    end tell

    do shell script ("ditto -c -k --sequesterRsrc --keepParent " & quoted form of POSIX path of theItem & space & quoted form of (POSIX path of destFolder & itemName & ".zip"))
on error theError
    tell me
        activate
        display dialog "Error: " & theError buttons {"OK"} default button 1 with icon stop
    end tell
end try
like image 30
Parag Bafna Avatar answered Oct 22 '22 02:10

Parag Bafna