... back


Good news, everyone




Creating Zip files omitting .DS_Store files

Darn m*therflippin' hidden .DS_Store records. Y u spoil me zip files?!

Each time I am using MacOS X there is this one issue: Zipped files always contain those unwanted, annoying .DS_Store files. You don't even recognize them if you are using MacOS X on the target system too, but dare you using Windows or any Linux/UNIX system ... suddenly they are everywhere.


Do your customers/friends/family a favor: pack clean Zip files that do not contain hidden system relicts.


You can use this script in MaxOS' Automator.

Here comes the Script

It is a simple Bash script (sorry for bad style):
#!/bin/bash
#
# To create the desired zip file inside the current Finder window's
# working directoy, this script just places it inside the first
# passed file's parent directory.
# 
# 'pwd' is not doing the job here.


# Check if input args are present
if [ $# -lt 1 ]; then
    echo "Pass some files" 1>&2
    exit 1;
fi

get_abs_filename() {
  # $1 : relative filename
  echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
get_base_directory() {
  # $1 : relative filename
  echo "$(cd "$(dirname "$1")" && pwd)"
}


baseDir=$(get_base_directory $1)
echo "baseDir=$baseDir"
cd "$baseDir"
pwd

# Convert absolute paths to plain file names
filenamelist=()
for f in "$@"
do
	echo "Current file=$f, basename=$(basename "$f")"
  	filenamelist+=( "$(basename "$f")" )
done
# echo "filenamelist: $filenamelist"

# Convert the filenamelist into a string (whitespace separated)
filelist=$(echo ${filenamelist[*]})
echo "filelist=$filelist"

zipName="$(basename "$baseDir").zip"

# Eventually create the zip file
zip -r "$zipName" $filelist -x "*.DS_Store"



Download bash script here.


Have fun!


Enjoy and don't forget to help your friends!