Am trying to put together a shell script that will find files between two dates.
The script below compiles but doesn’t find the files.
Obviously I am doing something incorrectly.
set parentfolder to path to documents folder from user domain as string
set ppath to quoted form of POSIX path of parentfolder
set Bgn to "31-Dec-09"
set ABgn to date Bgn ------ date for search to begin
set dNe to "04-May-10"
set AdNe to date dNe -------date for search to end
set SearchItm to "With These Words in it's Name" -------- Search Item
set theFiles to (do shell script "mdfind -onlyin " & ppath & " 'kMDItemDisplayName == \"*" & SearchItm & "*\" && kMDItemContentModificationDate >= " & ABgn & " && kMDItemContentModificationDate <= " & AdNe & "'")
Have also tried this way - with no joy
set theFiles to (do shell script "mdfind -onlyin " & ppath & " 'kMDItemDisplayName == \"*" & SearchItm & "*\" && kMDItemContentModificationDate >= \"" & ABgn & "\" && kMDItemContentModificationDate <= \"" & AdNe & "\"'")
Any help greatly appreciated.
Val
Model: iMac8,1
AppleScript: 2.3 (118)
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
Have you used mdls to be certain that you’ve formatted the dates as Spotlight does?
set J to do shell script "mdls " & quoted form of POSIX path of (choose file)
-->
kMDItemContentCreationDate = 2005-06-17 13:23:14 -0300
kMDItemContentModificationDate = 2005-06-17 13:23:14 -0300
kMDItemContentType = "public.jpeg"
kMDItemContentTypeTree = (
"public.jpeg",
"public.image",
"public.data",
"public.item",
"public.content"
)
kMDItemDisplayName = "A400.jpg"
kMDItemFSContentChangeDate = 2005-06-17 13:23:14 -0300
kMDItemFSCreationDate = 2005-06-17 13:23:14 -0300
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = 0
kMDItemFSLabel = 0
kMDItemFSName = "A400.jpg"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 502
kMDItemFSSize = 0
kMDItemFSTypeCode = ""
kMDItemKind = "JPEG image"
kMDItemLastUsedDate = 2010-05-04 20:49:27 -0300
kMDItemUsedDates = (
2005-06-17 04:00:00 -0300,
2007-12-12 00:00:00 -0400,
2008-01-13 00:00:00 -0400,
2009-09-23 00:00:00 -0300,
2010-05-04 00:00:00 -0300
)
Excellent. Many thanks.
I should have read your Lesson Using Spotlight in your AppleScripts at http://macscripter.net/viewtopic.php?id=24765 more thoroughly.
The up-dated script which seems to work is as follows:
set parentfolder to path to documents folder from user domain as string
set ppath to quoted form of POSIX path of parentfolder
set Bgn to "31-Dec-09" ---- date for search to begin
set ABgn to round ((current date) - (date Bgn)) / 86400 ----- time from begin search to now in days (rounded)
set dNe to "04-May-10" ---- date for search to end
set AdNe to round ((current date) - (date dNe)) / 86400 ----- time from end search to now in days (rounded)
set SearchItm to "With These Words in it's Name" -------- Search Item
set theFiles to (do shell script "mdfind -onlyin " & ppath & " 'kMDItemDisplayName == \"*" & SearchItm & "*\"&& kMDItemContentModificationDate >= $time.today(-" & ABgn & ") && kMDItemContentModificationDate <= $time.today(-" & AdNe & ")'")
Unix - no real knowledge - just adjusting other peoples contributions to suit the purpose on hand.
Thanks again,
Val