infotexture // Information Architecture & Content Strategy


Automator Workflow: Set ZIP File Date

When you compress a file or folder in the Finder via the Create Archive command, a ZIP file is created using the current date as modification date.

But when you’re archiving older data, it’s much more useful for the ZIP file date to reflect the date of its contents, since a few years from now you probably won’t care when you compressed the stuff, but rather how old the files inside are.

Fortunately, the command line version of ZIP included in Mac OS X includes an option to do just this: zip -o, which according to the man page will

Set the “last modified” time of the zip archive to the latest (oldest) “last modified” time found among the entries in the zip archive

—which is just what we want.

But depending on your command line proficiency, you may find it a bit tedious to open up a terminal window and look up the command syntax every time you need to compress a file.

Enter Automator, one of the most useful (and unsung) productivity tools in OS X, which we’ll use to create a new Finder plug-in (or “workflow”).

To create the workflow, open /Applications/Automator.app and add three actions in this order:

  1. From the Finder library, drag the Get Selected Finder Items action to the workflow area on the right side of the window.
  2. Drag the Create Archive Finder action to the workflow area, placing it after the first action.

    (At this point, you can pre-specify a name and location for the archive file, or set the Options to prompt for this information when the workflow runs.)

  3. From the Automator library, add the Run Shell Script action. Leave the Shell set to /bin/bash, set Pass input to as arguments, and replace the default script in the text box with zip -o "$@".

That’s it!—Save the workflow as a Finder Plug-in, and you can run it on files & folders in the Finder by Control-clicking and choosing your new command from the Automator submenu in the shortcut menu.