Use an AppleScript droplet for easier compression

Sep 28, '04 09:44:00AM

Contributed by: troger

I came across some hints on using the ditto command to create .zip files and people were doing it with folder action scripts. I figured why not just make it a droplet? Copy and paste the following into Script Editor and save it as an application:

on open (theItems) --receive items dropped onto droplet as a list
  --incase you're trying to compress something really big on your Rev A iMac:
  with timeout of 1000000 seconds
      tell application "Finder"
        --repeat the command to compress each item as an individual archive
        repeat with oneItem in theItems
          --used to extract the name and location of the file
          set itemProp to properties of oneItem
          --where the file is
          set itemPath to quoted form of POSIX path of oneItem
          --where the compressed file should end up
          set destFold to quoted form of POSIX path of 
            (container of itemProp as alias)
          --what the name of the file is
          set itemName to name of oneItem
          --do it, do it now
          do shell script 
            ("ditto -c -k -X --rsrc --keepParent " & itemPath & 
              " " & destFold & "'" & itemName & "'" & ".zip")
        end repeat
      end tell
    on error errmsg
      --should anything go wrong let the user know
      display dialog errmsg
    end try
  end timeout
end open
[robg adds: This works as described. It does not, however, create one archive from multiple dropped files. Instead, each dropped file will create its own zip file.]

Comments (4)

Mac OS X Hints