@Files Move Files Based on Creation Date

###MACRO:   @Files Move Files Based on Creation Date

~~~ VER: 1.0    2017-08-11 ~~~

@Files Move Files Based on Creation Date.kmmacros (22 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.

###Use Case

  • Move Files from a Source Folder to a Destination Folder based on File Creation Date

###Example Output

####Finder BEFORE Move

####Choose Destination Folder

####Confirm Creation Date, and Proceed

####Finder AFTER Move




  • MOVE Files Based on Creation Date

NOTICE: This macro/script is just an Example

  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.


  1. In the Finder, select the file with the oldest Creation Date that you want to move.
  • The Source Folder, and Creation Date will be determined from this selection
  1. Trigger this Macro
  2. Confirm the Creation Date to use, and click OK
  3. The macro will now move the files, and show the Destination folder in the Finder.


  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro. This is probably the Finder Group.
  • ENABLE this Macro.
    (all shown in the magenta color)
    • GRP: Set or Choose Destination Folder

TAGS: @Search @Files @Folder @Move @ShellScript


  • Any Action in magenta color is designed to be changed by end-user


  • To facilitate the reading, customizing, and maintenance of this macro,
    key Actions are colored as follows:
  • GREEN -- Key Comments designed to highlight main sections of macro
  • MAGENTA -- Actions designed to be customized by user
  • YELLOW -- Primary Actions (usually the main purpose of the macro)
  • ORANGE -- Actions that permanently destroy Variables or Clipboards,
    OR IF/THEN and PAUSE Actions


  1. Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
  2. El Capitan 10.11.6+
  • It make work with Yosemite, but I make no guarantees.


  • While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

###Bash Shell Script

find "$KMVAR_MFB__SourceFolder" -type f -maxdepth 1 -newerBt "$KMVAR_MFB__CreationDate"

This uses the very powerful, very flexible Bash find command.
Here's how it breaks down:

"$KMVAR_MFB__SourceFolder" The Folder to start the search in
-type f Restricts the search to only files
-maxdepth 1 Restricts to Parent Folder (no subfolders)
-newerBt "$KMVAR_MFB__CreationDate" Restricts to files with Creation Date on/after

For more info, see [BASH] find Command -- Mac OS X Manual Page

###TIP: Convert Unix File Time to ISO/ICU Date Format

Here's a tip on handling file dates that you get from the KM Action:

This will return the file date/time in Unix format, like this:

To turn that into something us humans can read, use the %ICUDateTimeFor% token in a Set Variable Action, like this:
%ICUDateTimeFor%MFB__CreationDate%yyyy-MM-dd HH:mm%

which results in:
2017-07-15 14:16

1 Like

Would it be possible to select the trash as a destination option?
Also would like to move files before a certain date, not after, to the trash…
Of course this is to be used with caution.
I have a folder of backups that I clean out once a month.
So I would like the older backups, or files before a month ago, to be moved to the trash.
good stuff, thanx

Easy enough.

  1. Remove the Prompt for Destination Folder

  2. Change the Move files Action to "Trash":

Again, easy enough. A simple change to the find command:

To use the Creation Date:
find "$KMVAR_MFB__SourceFolder" -type f -maxdepth 1 ! -newerBt $KMVAR_MFB__Date

To use the Modification Date:
find "$KMVAR_MFB__SourceFolder" -type f -maxdepth 1 ! -newermt $KMVAR_MFB__Date

The key changes here are:

  1. Use of the NOT operator: !
    which will mean NOT newer than the specified date (or, PRIOR to the specified date).
  2. Setting the newer parameter based on the date field you want to use:
  • newerBt for Creation Date
  • newermt for Modification Date

So, while the basic changes are relatively simple, putting it all together in a safe manner requires quite a few other changes. Thus, I have made a new Macro just for selecting and moving the files to Trash.

See: MACRO: @Files Trash Files PRIOR to Date Specified @Example


Nice! I’m on the road so will check all this out when I get back.