Is there a way to automate creation of ZIPs containing files with common name elements?

What I have are multiple variations of the same image:






What I'd like to do is create some sort of application that goes into folders, finds related files (all contain "8199") and then archives them all into a new file named "cartoon8199.zip".

I tried to create an Application via Automator, but couldn't figure out how to make the Name Contains field in Find Finder Items include a variable.

Any ideas on how to achieve this?

I'm on a Mac running HighSierra 10.13.3.

Thanks in advance!

  • I should have specified, the resulting ZIP files would go in different folder named files/zips
    – Andertoons
    Commented Jun 25, 2018 at 19:21
  • Do you want to go check specific folders or go through the entire drive? Commented Jun 25, 2018 at 19:29
  • Specific folders only.
    – Andertoons
    Commented Jun 25, 2018 at 19:31
  • Specific folders recursively or just specific folders? Commented Jun 25, 2018 at 19:33
  • Just 5 specific folders (I think. As you can probably tell, I'm no coder. But I am a fast learner!)
    – Andertoons
    Commented Jun 25, 2018 at 19:56

1 Answer 1


Heres your script as promised. Any questions or suggestions? Comment below :)

What the script does: Searches through a selected folder for folders. Searches through each one of those for files. If those files contain a specified search parameter then the file is moved to a folder in a location specified. Once all files are checked, the files in the folders at the location specified is ziped up.

For what you want: First Prompt choose the /files folder. In the second prompt enter 8199.

The Script:

set myFolder to choose folder with prompt "Choose a Folder" # Choose the /files folder
display dialog "Enter Your Search Paramaters" default answer "" #Enter "8199"
set mySearch to the text returned of the result
set myZipLocation to the POSIX path of (choose folder with prompt "Choose where to save your ZIP file")
display dialog "Enter the Name of Your Compress File" default answer ""
set myZip to the text returned of the result
tell application "Finder"
    set myFolders to every folder in folder myFolder
    set myFiles to {""}
    repeat with i in myFolders
        set myFiles to myFiles & every file in i
    end repeat
    do shell script ("mkdir " & the quoted form of (myZipLocation & "/" & myZip))
    repeat with i from 2 to count of myFiles
        if the name of (item i of myFiles) contains mySearch then
            set myPOSIX to the quoted form of (the POSIX path of (item i of myFiles as alias))
            do shell script "cp " & myPOSIX & " " & the quoted form of ((myZipLocation & "/" & myZip) & "/" & the name of (item i of myFiles))
        end if
    end repeat
    do shell script "cd " & the quoted form of myZipLocation & "&& zip -r " & quoted form of (myZip & ".zip") & " " & quoted form of myZip
end tell
  • @Andertoons How’d it work? Commented Jun 26, 2018 at 19:54
  • @Andertoons Great! Glad I could help. If this solve your problem please upvote and mark as solved to help other users find this answer. Commented Jun 27, 2018 at 22:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .