Automator - how do I zip a folder 'with replacing'?

Automator - how do I zip a folder 'with replacing'?

I have an action that selects a folder - then create archive in a chosen folder


Currently - it uses the source folder name then makes new archives each time like:


my folder.zip

my folder 1.zip

my folder 2.zip


I would rather there was only one zip and the new version would ALWAYS OVERWRITE the old.


Q: How can I get this happening?


or how do i do this with applescript?

MacBook Pro, OS X El Capitan (10.11.5)

Posted on May 30, 2016 9:17 AM

Reply
2 replies

May 30, 2016 11:36 AM in response to revDAVE

Hi,



In an Automator workflow, you can use this script into the "Run AppleScript" action.


----

on run {input, parameters} -- script for Automator

-- create an archive in the parent folder, it use the name of the folder, it overwrite an existing archive and return the path of the archive

return fileZipper(item 1 of input) -- input is a list and it contains the path of the folder

end run


on fileZipper(thisItem)

set tPath to thisItem as text

if tPath ends with ":" then

set oTid to text item delimiters

set text item delimiters to {":"}

set tPath to text 1 thru text item -2 of tPath

set text item delimiters to oTid

end if

set zipFile to (tPath & ".zip") as text

do shell script "/usr/bin/ditto -c -k -rsrc --keepParent " & (quoted form of POSIX path of tPath) & " " & quoted form of POSIX path of zipFile

return zipFile as alias

end fileZipper

-----


This script create a new archive or overwrite an existing archive with the same name that the folder.

The destination is the parent folder of your selected folder.


if you want to move this archive to a specific folder, add the "Move Finder Items" action after the "Run AppleScript" action.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator - how do I zip a folder 'with replacing'?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.