Question

I have an action to zip a folder with no compression, so I'm using applescript. However, my original script line creates the archive using the full path from Users folder:

do shell script "zip -r0 " & zipFile & " " & itemPath

I'm trying to get cd to work, but with no success:

Basically, I want the zip folder to:

Be named the same as the source folder, be created in the same directory as the source folder, be archived with the folder structure intact, use relative paths using the source folder as the root, and finally, have no compression

Here's the full script:

on run {input, parameters}
    set folderName to (input as text)
    tell application "Finder"
        set theItem to folderName as alias
        set itemPath to quoted form of POSIX path of theItem
        set fileName to name of theItem
        set theFolder to POSIX path of (container of theItem as alias)
        set zipFile to quoted form of (theFolder & fileName & ".zip")
        do shell script "cd " & theFolder / "zip -r0 " & zipFile & " " & itemPath
    end tell
    return input
end run

Any help very gratefully received.

R

Was it helpful?

Solution

Try to use a Run Shell Script action like this instead:

for f;do cd "${f%/*}";zip "${f##*/}.zip" -x .DS_Store -r0 "${f##*/}";done

${f%/*} removes the shortest /* pattern from the end of f and ${f##*/} removes the longest */ pattern from the start of f.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top