5

When compressing files/folders in Finder, via the context menu, i.e. select the files/folders then right-click and select Compress ..., a hidden folder named __MACOSX is created within the zip archive.

How can the hidden folder named __MACOSX not be created within the zip archive?

  • Welcome to Ask Different. :) Unfortunately, your question doesn't provide enough detail for us to help you. Reading how to ask a question may improve your chances of getting a good answer. For now, can you please edit your question to clarify what is actually happening. Specifically, can you expand on what you mean by a hidden folder being created? Is this located within the archive? Or do you mean you get nothing but an empty folder (i.e. nothing is being archived)? Or something else? – Monomeeth Jul 2 '17 at 11:50
  • 1
    By default, files/folders compressed in Finder are proceeded using Archive Utility and this app does not have the setting preferences to keep meta-data from bring added to the archive. You'll have to use a third-party solution or other macOS built-in utilities/methods, i.e. using command line utilities like ditto, zip or creating an Automator Service to perform the actions necessary to achieve the goal, etc. – user3439894 Jul 2 '17 at 13:20
  • What version of OS X/macOS are you using? – user3439894 Jul 2 '17 at 16:22
6

Using info from the other answer, here's an Automator Service1 that becomes available in Finder to delete the "__MACOSX" meta-data folder from a zip archive file.

To Create the Service:

  1. Open Automator and select: File > New > Service

  2. Set Service receives selected to files or folders and in to Finder.

  3. Add a Run Shell Script Action, setting Shell: to /bin/bash and Pass input: to as arguments while replacing the default code with the following code:

    for f in "$@"; do
        if [[ ${f##*.} =~ ^[zZ][iI][pP]$ ]]; then
            zip -d "$f" "__MACOSX*"
        fi
    done
    afplay /System/Library/Sounds/Purr.aiff
    
    • What the code does: It checks that each file passed to the service has a zip extension, regardless of case, and if it has a zip extension, and if "__MACOSX" exists within the zip archive, deletes the "__MACOSX" meta-data folder from the zip archive.

    • ${f##*.} gets the file extension, =~ tests the regex, and the ^[zZ][iI][pP]$ regex matches any case combination of each letter within the square braces while ^ asserts position at start of the string and $ asserts position at the end of the string. So it only matches zip in any case combination of those letters.

    • Note: The last line of the code is optional, just to let you know the service completed, and can be changed to a different sound or omitted if you prefer not to be notified by sound upon completion.

  4. Save the Service as, e.g.,: Delete '__MACOSX' from Zip Archive

1 In macOS Mojave, and later, an Automator Service is called a Quick Action. There are also other minor nomenclature differences but they should be more obvious when comparing them to pre-macOS Mojave Automator workflows.

To Use the Service:

In Finder, or on the Desktop if the zip archive is located there, select the zip archive(s), then right-click and select Delete '__MACOSX' from Zip Archive from the context menu or under Services on the context menu, or from Services on the Finder menu as appropriate.

The image of the service in Automator, below, is from OS X 10.8.6, however, it was tested under macOS 10.12.5 and works there as well.

Automator Service

  • Well done. Would you mind me making an edit to explain why these folders properly exist when you encode HFS+ files or speculations that be better as it’s own answer? – bmike Jul 2 '17 at 20:08
  • @bmike, Not at all, sounds like value added... thanks. – user3439894 Jul 3 '17 at 1:19
  • Its Great. Thank you ii work. is it possible that service will compress and delete the files. all in one click? – Roei Hazout Jul 6 '17 at 9:43
2

From WP Guru - How to remove __MACOSX from zip archives

First, create your ZIP via the finder – like you always do. Next, open Terminal and cd into the directory where your ZIP file is located. If it’s a long path, just type “cd “, then drag the folder into Terminal (less typing is always good).

Now type the following:

zip -d your-archive.zip "__MACOSX*"

And that should do it. This command (zip) will remove everything (-d) starting with __MACOSX from your ZIP file (your-archive.zip).

To verify, type the following:

unzip -l your-archive.zip

This will simply list the contents of your-archive.zip.

If you're not comfortable with Terminal, BetterZip has an option to do this for you, but it's $25.

  • I would like to totally disable this option. – Roei Hazout Jul 2 '17 at 12:39
  • 1
    I doubt that's possible. The data is there for the OS to be able to correctly re-merge metadata that cannot be carried in the files otherwise. – Tetsujin Jul 2 '17 at 12:45
2

Like user3439894 said, try third-party solution. I'm using free application Keka with success, long term:

http://www.kekaosx.com/en/

Configure in Keka preferences to not create mac-specific files in archives. It can also be used via the context menu (after adding "Compress with Keka.workflow" to your "~/Library/Services" folder), see the link at the bottom left of their website.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .