Using ‘kMDItemContentModificationDate’ in ‘do Shell Script’

applescriptcommand line

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.

Best Answer

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 & ")'")