How can I sort Mac files by modified?*
August 4, 2011 4:40 AM   Subscribe

Can I search my Mac by relative creation/modified date?

For a recurring project, I often need to examine a long list of files to determine if I've touched them since creation. The way I do it now is sort by Creation Date with Last Modified visible, and run my eyes up and down the list… if the difference is less than 1 hour, I assume that they're still in their original state, and if not, I assume I've edited them. Not ideal, not the least because the numbers all run together, and I've got to sort between days and AM/PM

Is there a way I can use a smart folder or some other search mechanism to quickly determine which files are new-ish? All I want 'time between creation and last modified is ≤1 hr.'

Snow Leopard, but if Lion can do it, I'd love to know about that too.
posted by mhz to Computers & Internet (8 answers total)
There may be a better way, but you could use Hazel for this. You an choose "Date Last Modified is not in the last X minutes/hours/days/weeks".

You could go a step further and have it mark all the recently modified items with a different colour label, or move them to a separate folder, etc.
posted by backwards guitar at 5:01 AM on August 4, 2011

If you're able to use the Terminal for this, you can do something like:

find /path/to/files -mtime -1h

That will show all files in /path/to/files that were changed within the past 1 hour.
posted by chengjih at 5:29 AM on August 4, 2011

Response by poster: Hazel doesn't seem to do what I want…

Because it constantly updates, I need something that just works live. The Terminal trick only works in the last hour, not in the hour difference between creation and modification times.

I pulled 8 random from the folder I'm working with:

Date Modified - - - - - Date Created
Today 2:54 PM - - - - - Today 2:46 PM
Today 2:32 PM - - - - - Today 2:24 PM
Today 9:54 AM - - - - - Yesterday 9:34 PM
Yesterday 9:26 PM - - - Yesterday 9:18 PM
Today 8:04 AM - - - - - Yesterday 11:29 AM
Aug 2, 2011 5:28 PM - - Aug 2, 2011 5:22 PM
Today 8:31 AM - - - - - Aug 2, 2011 1:22 PM
Aug 1, 2011 10:09 AM -- Jul 31, 2011 10:10 AM

In this example, I'd want to highlight, or put in a smart folder, the 1st, 2nd, 4th, & 6th files.
posted by mhz at 5:49 AM on August 4, 2011

I'd be looking into AppleScript, but it helps that I know some AppleScript.

You'd want to iterate over a directory, get your two dates, compare, and if the delta was greater than your threshold, tell the finder to apply a label to your file.

Once I had a script I could run on demand, I'd look at creating two more parts:
1: A folder action to do this on any change to the folder.

2:a smart folder based on location (your target directory) and label.
posted by Mad_Carew at 6:19 AM on August 4, 2011

Response by poster: Applescript looks promising, but I don't think I'll figure it out in time… maybe next time the project comes around.

I don't see how versioning helps me for this. I'm using an application which doesn't usually have great support for OS X's newest features (and I'm not even using their current generation of software), and versioning needs to be implemented specifically (like Spotlight or Quicklook, unlike Time Machine). Even with versioning, I don't see how I can get a quick look at what I'm looking for.
posted by mhz at 8:13 AM on August 4, 2011

Best answer: Try this in a Terminal:
stat -f '%B %m %N' * | while read -r born mod name; do ((mod-born<=3600)) && echo "$name"; done
Not tested as I don't have a Mac. I'm hoping that the "inode born" time documented in the stat manpage is the file creation time (I'm on Linux which doesn't keep those and has different options for stat).
posted by flabdablet at 10:12 AM on August 4, 2011

flabdablet: This sort of works for me on OS X Lion (except I changed your less than sign to a greater than). However, it seems to depend on the program used to modify the file. TextEdit worked well (left the "born" date alone and updated the "modified" one), but Mac Vim updated the "born" date to the current time as well. So I'm not sure if it would work for OP, necessarily.

OP: flabdablet's solution might work for you, depending on the program you're using to modify the files. Note that you'll have to switch the "less than or equal" sign to a "greater than or equal" sign. If you're comfortable navigating to the folder in the Terminal, then fire away. However, here's how you can use it, if you've not used the Terminal before:

1) Open the Terminal. (Probably easiest to launch from Spotlight).

1) Type the first part as flabdablet says, "stat -f '%B %m %N' " and leave a space.

2) Use the Finder to navigate to the folder you're interested in.

3) Drag that folder from the Finder onto the Terminal. Terminal will type in the pathname to that folder for you.

4) Type (or copy-paste) the rest of flabdablet's script, being sure to switch the less-than to a greater-than.

5) Hit enter. The files whose modification date is more than one hour newer than their creation date should be listed.
posted by losvedir at 2:14 PM on August 4, 2011

TextEdit worked well (left the "born" date alone and updated the "modified" one), but Mac Vim updated the "born" date to the current time as well.

When you write out a file with Vim, its default action is to rename your old file and write everything to a new one; that way, if you run out of disk space or something else bad happens during the save, at least it can recover your original. Most apps are not so careful.

So I'm not sure if it would work for OP, necessarily.

It should be pretty much an exact automation of the process the OP has been doing by eye, though. Also, the OP did ask for 'time between creation and last modified is ≤1 hr.' which I believe is what my script does without modification.
posted by flabdablet at 5:26 PM on August 4, 2011

« Older Identify this song: Camarero   |   Trying to find an old scifi short story about time... Newer »
This thread is closed to new comments.