Skip to main content
Modified code and added macos Mojave note.
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

Here is an Automator Service1 that becomes available in Finder when Folders are selected and emulates the context-menus Compress [n] Items command except it creates an individual zip archive file for each selected Folder in the name of the selected Folder. If the Folder Name.zip file already exists then a " 2" (space 2) is appended to the filename, e.g. Folder Name 2.zip. This ensures an existing zip archive file is not touched and the zip archive filename will be automatically incremented as necessary.

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 Create the Service:1

  1. Open Automator and select Service1 or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushdcd "$dn" || exit
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn *.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $nn + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

Image of Compress Folders Separately (Service)

Compress Folders Separately - Automator ServiceCompress Folders Separately - Automator Service

Here is an Automator Service that becomes available in Finder when Folders are selected and emulates the context-menus Compress [n] Items command except it creates an individual zip archive file for each selected Folder in the name of the selected Folder. If the Folder Name.zip file already exists then a " 2" (space 2) is appended to the filename, e.g. Folder Name 2.zip. This ensures an existing zip archive file is not touched and the zip archive filename will be automatically incremented as necessary.

To Create the Service:

  1. Open Automator and select Service or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushd "$dn"
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn *.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

Image of Compress Folders Separately (Service)

Compress Folders Separately - Automator Service

Here is an Automator Service1 that becomes available in Finder when Folders are selected and emulates the context-menus Compress [n] Items command except it creates an individual zip archive file for each selected Folder in the name of the selected Folder. If the Folder Name.zip file already exists then a " 2" (space 2) is appended to the filename, e.g. Folder Name 2.zip. This ensures an existing zip archive file is not touched and the zip archive filename will be automatically incremented as necessary.

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 Create the Service:1

  1. Open Automator and select Service1 or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         cd "$dn" || exit
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn *.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

Image of Compress Folders Separately

Compress Folders Separately - Automator Service

Removed `popd` as unnecessary and corrected a fatal typo in `for i in $bn*.zip; do` should have been: `for i in $bn *.zip; do`
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135
  1. Open Automator and select Service or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushd "$dn"
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn*$bn *.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
         popd
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

Compress Folders Separately - Automator ServiceCompress Folders Separately - Automator Service

  1. Open Automator and select Service or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushd "$dn"
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn*.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
         popd
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

Compress Folders Separately - Automator Service

  1. Open Automator and select Service or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushd "$dn"
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn *.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

Compress Folders Separately - Automator Service

Fixed typos.
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135

Here is an Automator Service that becomes available in Finder when Folders are selected and emulates the context-menus Compress [n] Items command except it creates an individual zip archive file for each selected Folder in the name of the selected Folder. If the Folder Name.zip file already exists then a " 2" (space 2) is appended to the filename, e.g. Folder Name 2.zip. This ensures an existing zip archive file is not touched. It and the zip archive filename will be automatically incremented as necessary.

  1. Open Automator and select Service or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushd "$dn"
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn*.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
         popd
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

In Finder or the on the Desktop select multiple Folders, then right-click and select Compress Folders Separately from under Services.

Or after selecting the target Folders, you can also click Finder > Services > Compress Folders Separately from the menu bar.

There you have it, a way to compress multiple folder separately and simultaneously at one time in individual zip archives while emulating how Finder creates a zip archive file. Meaning the zip archive contains preserved resource forks and HFS meta-data in the subdirectory __MACOSX and embeds only the parent directory name source in destination-archive, not the fully qualified pathname as when using zip (without -j}) to create the archive.

Here is an Automator Service that becomes available in Finder when Folders are selected and emulates the context-menus Compress [n] Items command except it creates an individual zip archive file for each selected Folder in the name of the selected Folder. If the Folder Name.zip file already exists then a " 2" (space 2) is appended to the filename, e.g. Folder Name 2.zip. This ensures an existing zip archive file is not touched. It will be incremented as necessary.

  1. Open Automator and select Service or File > New > Service If Automator is already open.

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

  3. Add a Run Shell Script Action setting Shell: to /bin/bash and Pass input: to as arguments and add the following code.

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushd "$dn"
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn*.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
         popd
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

In Finder or the on the Desktop select multiple Folders then right-click and select Compress Folders Separately from under Services.

Or after selecting the target Folders you can also click Finder > Services > Compress Folders Separately from the menu bar.

There you have it, a way to compress multiple folder separately and simultaneously at one time in individual zip archives while emulating how Finder creates a zip archive file. Meaning the zip archive contains preserved resource forks and HFS meta-data in the subdirectory __MACOSX and embeds only the parent directory name source in destination-archive, not the fully qualified pathname when using zip (without -j} to create the archive.

Here is an Automator Service that becomes available in Finder when Folders are selected and emulates the context-menus Compress [n] Items command except it creates an individual zip archive file for each selected Folder in the name of the selected Folder. If the Folder Name.zip file already exists then a " 2" (space 2) is appended to the filename, e.g. Folder Name 2.zip. This ensures an existing zip archive file is not touched and the zip archive filename will be automatically incremented as necessary.

  1. Open Automator and select Service or File > New > Service If Automator is already open.

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

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

     for f in "$@"; do
    
         dn="$(dirname "$f")"
         bn="$(basename "$f")"
    
         pushd "$dn"
    
         if [[ ! -e "$bn.zip" ]]; then
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn.zip"
         else
             n=2
             for i in $bn*.zip; do
                 if [[ "$bn $n.zip" == "$i" ]]; then
                     n="$(( $n + 1 ))"
                 fi
             done
             ditto -c -k --sequesterRsrc --keepParent "$f" "$bn $n.zip"
         fi
    
         popd
    
     done
    
     afplay /System/Library/Sounds/Purr.aiff
    
  4. Save the Service as: Compress Folders Separately

In Finder or on the Desktop select multiple Folders, then right-click and select Compress Folders Separately from under Services.

Or after selecting the target Folders, you can also click Finder > Services > Compress Folders Separately from the menu bar.

There you have it, a way to compress multiple folder separately and simultaneously at one time in individual zip archives while emulating how Finder creates a zip archive file. Meaning the zip archive contains preserved resource forks and HFS meta-data in the subdirectory __MACOSX and embeds only the parent directory name source in destination-archive, not the fully qualified pathname as when using zip (without -j) to create the archive.

Added images of Automator Service and additional info.
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135
Loading
Improved code to handle existing zip archive file and reworded answer accordingly.
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135
Loading
added 312 characters in body
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135
Loading
Source Link
user3439894
  • 59.8k
  • 10
  • 112
  • 135
Loading