sindresorhus/Actions

Action proposal: Compress Without Meta

Opened this issue ยท 0 comments

Description

Hi ๐Ÿ‘‹๐Ÿป

I'm fan of you work. Recently, I was developing Action that compresses the files & folders like mac's native compress feature (when we right click on files and directories) without meta directories like __MACOSX and .DS_Store. I created myself but somehow it doesn't work on Documents & Downloads dir and don't know how to resolve it.

But Why?

When we send zip to non-mac users they get unwanted __MACOSX and .DS_Store directories.


Hence, I'm raising this feature request in this actions to get them as a package.

Here's my existing work of shell script:

# Function to create zip file name based on inputs
create_zip_name () {
    if [ "$#" -eq 1 ]; then
        # Single file or directory
        inputPath="$1"
        inputBaseName=$(basename "$inputPath")

        if [ -d "$inputPath" ]; then
            echo "${inputBaseName}.zip"
        elif [ -f "$inputPath" ]; then
            echo "${inputBaseName%.*}.zip"
        fi
    else
        # Multiple files or directories
        echo "Archive.zip"
    fi
}

# Initial directory and zip file setup
initialDir=$(dirname "$1")
cd "$initialDir"
zipFileName=$(create_zip_name "$@")

# Execute zip command excluding unwanted metadata files
zip -r "$zipFileName" "${@#$initialDir/}" -x '**/__MACOSX' -x '**/.DS_Store'

# Use AppleScript to select the ZIP file in Finder
osascript -e 'tell application "Finder"' -e "activate" -e "select POSIX file \"$(pwd)/$zipFileName\"" -e 'end tell'
Screenshot

Screenshot 2024-02-29 at 11 36 07โ€ฏAM