Skip to main content

How to stop the hidden __MACOSX folder from being created when compressing files/folders in Finder [Resolved]

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?


Question Credit: Roei Hazout
Question Reference
Asked September 7, 2019
Tags: , folders
Posted Under: Apple
25 views
3 Answers

Using info from the other answer, here's an Automator Service 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 Workflow receives current 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

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

* In macOS Mojave and later, the Service option is now referred to as a "Quick Action".


credit: Monomeeth
Answered September 7, 2019

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.


credit: Tetsujin
Answered September 7, 2019

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.


credit: rudo.ba
Answered September 7, 2019
Your Answer