Zip each Folder and File Individually

This droplet is an applescript, for Mac users.

Simply drag and drop folders and files onto this droplet to create individual zips of each.

Download Droplet: ZIP EACH (23 downloads)

Tip: Easiest way to use this is to put it in Finder’s Toolbar. Just hold down the command key and then click and drag the application Zip Each to the top of Finder

Script:
At  my job, I often need to zip up several folders into their own zip file to be archived. I started to write this script and I found it was already shared on a website by Jim Mitchell: APPLESCRIPT TO COMPRESS FILES AND FOLDER. The great thing with scripting is so many people share their code and help others fix errors. Most commands you need can be found with a quick google search. I took the script from Jim’s website and made it into a droplet. With an investment of just a few minutes, I was able to avoid the frustration of “I wish” and create it.

I added many annotations for those who are trying to learn applescript.

--The 'on open' command turns the script into a droplet. Drag and drop folders/files onto the icon for this script to create an individual zip for each.
-- theList is a variable that contains a list of all the folders/files that are dropped onto the icon.
on open theList

-- In this script, all the actions will be performed by the Finder.
 tell application "Finder"

--Use a 'repeat' to repeat the code within the repeat/end repeat for each item in the list (variable theList)
-- The variable i is a number. On the first round it will be 1, as defined by: 'from 1'.
-- to (count of theList) lets the repeat know that the number of times it should repeat the code within the repeat/end repeat is the same number as the number of items in theList
 repeat with i from 1 to (count of theList)

-- Define which item from theList will be used. Using variable i is the same as 'item 1 of theList'. Each time the repeat cycles through the variable i will increase by one. So the second time around it will be 'item 2 of theList'.
 set theItem to (item i of theList) as alias

-- Get the loctation(path) to theItem. 
 set itemPath to quoted form of POSIX path of theItem

-- Get the name of theItem. The script will use this to name the zip file.
 set fileName to name of theItem

-- Get the folder that the folder/file is in. The script will use this to save the zip in the same location as the original folder/file
 set theFolder to POSIX path of (container of theItem as alias)

-- String together theFolder and fileName and ".zip" to create the path that will be used for the new .zip file
 set zipFile to quoted form of (theFolder & fileName & ".zip")

-- Finder doesn't have the ability to zip a file using applescript. Luckily we can use a shell script to accomplish it.
do shell script "zip -jr " & zipFile & " " & itemPath

 end repeat
 end tell
end open

Add your comment

Your email address will not be published. Required fields are marked *