0

I want to find files modified on a specific date. It is not important what time of day they were modified. I tried the following and got an empty list (no error):

set theFolder to (choose folder)
set folderPOSIX to quoted form of POSIX path of theFolder
set modList to paragraphs of (do shell script "mdfind -onlyin " & folderPOSIX & " 'kMDItemContentModificationDate = 2015-01-15 00:00:00 -0400'")

If I understand this correctly, I am asking for files in a specific folder (directory) which were modified on Jan 15, 2015. If I did this right (apparently not), it should find at least one file that was modified on that date, because I can see in the window of the folder I chose that there is a file modified on Jan 15.

Also, not sure what the -0400 part is for. Is there some way that I can get the files for Jan 15, regardless of the time of day they were modified.

  • I think -400 is the offset from GMT (i.e. the time zone) since at any given time, it's not the same date everywhere. You would usually want this to be the same GMT offset used on your Mac. – samh Feb 5 '15 at 16:18
  • Thanks for that much, I think you're absolutely right. In the meantime, while editing the time zone for my profile, I found EST listed as '-0400' – AppleScripter Feb 5 '15 at 16:56
  • Thanks, AppleScript is not my forte but I think your problem is that you're searching for times whose modification date and time are exactly 15 Jan 2015 at midnight. If there's not a separate date-only comparison, you'll need to do some kind of range (I don't know the applescript syntax, so it might mean two comparisons with a >= and a < or maybe there's a BETWEEN or RANGE kind of thing as there is with SQL). – samh Feb 5 '15 at 19:08
1

Came up with this solution with help of above script which works just fine:

set downloadPath to path to downloads folder from user domain as string
set posixPath to quoted form of POSIX path of downloadPath

--Date to search for:
set dateStart to text returned of (display dialog "Enter search date in form 'MM/DD/YYYY'" default answer "02/03/2015")
--date "Tuesday, February 3, 2015 12:00:00 AM"
set dateStart to date dateStart
--End date (Midnight on next day)
set dateEnd to (dateStart + 24 * 60 * 60 * 1)
--date "Wednesday, February 4, 2015 12:00:00 AM"

--Begin search to now in days (rounded)
set startRound to round ((current date) - dateStart) / 86400
--End search to now in days (rounded)
set endRound to round ((current date) - dateEnd) / 86400
--Search Item
set SearchItem to "."

set theFiles to (do shell script "mdfind -onlyin " & posixPath & " 'kMDItemDisplayName == \"*" & SearchItem & "*\"&& kMDItemContentModificationDate >= $time.today(-" & startRound & ") && kMDItemContentModificationDate <= $time.today(-" & endRound & ")'")
0

The following code does what you want. I found it here,

http://macscripter.net/viewtopic.php?id=32855

You may want to adjust the query to filter things further but it did work properly when I tested it quickly...

set parentfolder to path to downloads folder from user domain as string
set ppath to quoted form of POSIX path of parentfolder

# date for search to begin
set Bgn to "1-Dec-14"

# time from begin search to now in days (rounded)
set ABgn to round ((current date) - (date Bgn)) / 86400

# date for search to end
set dNe to "2-dec-14"

# time from end search to now in days (rounded)
set AdNe to round ((current date) - (date dNe)) / 86400

# Search Item
#set SearchItm to "With These Words in it's Name"
set SearchItm to "."

set theFiles to (do shell script "mdfind -onlyin " & ppath & " 'kMDItemDisplayName == \"*" & SearchItm & "*\"&& kMDItemContentModificationDate >= $time.today(-" & ABgn & ") && kMDItemContentModificationDate <= $time.today(-" & AdNe & ")'")
  • I'm not sure why this does not work on my computer. I get the error message: error "Invalid date and time date 1-Dec-14 of «script»." number -30720. I have my date and time prefs formatted like this: Month Day Year, but even if I change the format to Day Month Year, I still get the same error message. I am using Snow Leopard (10.6.8) – AppleScripter Feb 9 '15 at 15:13
  • Strange, I am using SL as well. Can only suggest trying different formats to find one that works... – Vic Feb 9 '15 at 19:49

You must log in to answer this question.

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