Smart folder, containing the photos of this date in history. HOW?

Dear comrades,
I badly need a smart folder with all the image files, whose creation date has the same day and month as today’s, from the past years. Let’s call this smart folder “This day in history”.
Unfortunately there’s no such criteria neither in smart folder editor, nor in Automator.
I beg you to give me piece of advice, how can I make it with help of AppleScript, if possible.
Thanks in advance, and excuse me if I post it to inappropriate thread.

Hi,

I think, there’s no way to do this.
Spotlight could only search for patterns like

searchresults = (date == today) or (date == today - 365) or (date == today - 365 * 2)

by editing the xml file manually but this raises another problem to consider leap years.

That’s a really cool idea; from my understanding of how things work, it’s probably not possible (but don’t take my word for it, I am an AppleScript n00b). I’d love to be proven wrong though, if for no other reason than that it would be a cool thing to show off the power of smart folders.

Hallo Stefan,
Vielen Dank, your code seems so logic :slight_smile: I created a smart-folder, pressed Cmd-I on it, and I can see the code of query string there, but where can I find its editable xml?
Although I didn’t understand, what did you mean by “leap years”?
(Keep in mind, I’m not a coder, when you explain :slight_smile:

Another idea of solution was as following:
I thought I could copy the creation date from EXIF to keywords, and then search by keywords, like “June, 4”. Search string in this case would consist of:
Variable1 = today’s day (number->string)
Variable2 = today’s month (string)
But I failed to insert the Variables into “Keywords contain” field of Automator’s “Search Finder Items” action. :frowning: Maybe wrong way with dead-end.

PS
Thank you for encouragement, Fooruman :wink: I won’t give up!

===========================
UPD:
OK Stefan, I just dragged smart-folder to TextEdit and now I can edit xml. I added some criteria just to see, what to edit.
Kind: Images
Size: >50KB
CreationDate: today

And the code (among other) is:
(((_kMDItemGroupId = 13) && (kMDItemFSSize > 51200) && InRange(kMDItemContentCreationDate,$time.today,$time.today(+1)))) && (true)

Could you edit this to contain your code please?

leap year = Schaltjahr (366 days).

Of course you can query the files one by one checking year and month but Spotlight (-> smart folders) can’t do it.

The smart folder is fake, it’s actually a xml file. Open it with the contextual menu > others > [any text editor]

Stefan, take a look at Update to my last message, please.

I actually don’t care about tool. Whether to manually tweak the spotlight xml-file, or to write an AppleScript scriptlet, that would pass the needed files to the following automator action in the workflow. I just need this array of photos with today’s day&month. And I need it ASAP for my project.

And the leap years don’t seem to be a problem for me. It would be even better to include the photos of 2-3 days around that day years ago. I.e. today-364, today-365, today-366, today-729, today-730, today-731 … and so on.

I’m sorry, my “code” is not real, it’s just a math example.

In AppleScript there is no way to use a whose filter for a date property like month or day,
you could only use a repeat loop which ist quite slow for a hugh amount of files

Hi

Here is the solution :
No need to edit the xml file.

To change the criteria for a Smart Folder, open it , open the Action (gear) menu and choose “Show Search Criteria”.

Removes attributes “created date”, click minus (-) button to remove attributes
adds a new attribute, click the plus (+) button to add attribute.
Select “Raw query” in the left popup, if not in the menu, select “others”, waits until the window appears, select “Raw query”.

Run this script :

set n_days to 0
set t_year to year of (current date)
set querycmd to ""

repeat with i from t_year to 1980 by -1 -- stop to year 1980, you can modify that
	tell i to if (it mod 4 = 0 and (it mod 100 > 0 or (it mod 100 = 0 and it mod 400 = 0))) then
		set n_days to n_days - 366
	else
		set n_days to n_days - 365
	end if
	set querycmd to querycmd & "kMDItemFSCreationDate >= $time.today(" & n_days & ") && kMDItemFSCreationDate < $time.today(" & (n_days + 1) & ") || "
end repeat
set the clipboard to text 1 thru -5 of querycmd

paste the clipboard in the “Raw query” text field.
Save the Smart Folder.

Each year, you need to change the attribute “Raw query” to avoid a day mismatch, due to leap year.

if you wanted a range of 3 days rather than one day, replace this line

set querycmd to querycmd & "kMDItemFSCreationDate >= $time.today(" & n_days & ") && kMDItemFSCreationDate < $time.today(" & (n_days + 1) & ") || "

by this

	set querycmd to querycmd & "kMDItemFSCreationDate >= $time.today(" & (n_days - 2) & ") && kMDItemFSCreationDate < $time.today(" & (n_days + 1) & ") || "

.

This is a great idea but unfortunately it doesn’t work right for me. Here’s why…

I obviously have all my images in iPhoto like most people. In 2004 I scanned in a bunch of photos from my childhood and set their date in iPhoto to be the date in my childhood. So iPhoto displays them with the proper date. The problem is that the FSCreationDate is still 2004 for these images instead of my childhood date… so this smart folder doesn’t find them properly and I have tons of scanned images like this because iPhoto and digital cameras weren’t available in my childhood. Maybe I’m just too old! :smiley:

The only solution would be if I manually edited the FSCreationDate of all these images but that’s too much effort as I have thousands.

So great idea but it doesn’t fit with my situation.

Hi

FSCreationDate : is the file creation date, but this is not the one in the EXIF “Date / Time Original”, Spotligtht does not have this Metadata Attribute.

But you can change the file creation date easily with a script.

If you have the Developer Tools installed and Leopard, this script works on iPhoto Version 6 or newer.

 iPhotoDateToFilesCreationDate()

on iPhotoDateToFilesCreationDate()
	script o
		property sel : {}
		property a_list : {}
	end script
	tell application "iPhoto"
		set o's sel to selection
		repeat with i in o's sel
			if class of i is album then
				set o's a_list to photos of i
				set tc to count o's a_list
				if tc > 0 then repeat with p from 1 to tc
					tell item p of o's a_list to my setcreationDate(image path, original path, date)
				end repeat
			else
				tell i to my setcreationDate(image path, original path, date)
			end if
		end repeat
	end tell
end iPhotoDateToFilesCreationDate

on setcreationDate(f, f2, d)
	tell (d as «class isot» as string) to set d to text 6 thru 7 & "/" & text 9 thru 10 & "/" & text 1 thru 4 & " " & text 12 thru 19
	if f is not f2 then
		set t to (quoted form of f) & " " & quoted form of f2
	else
		set t to (quoted form of f)
	end if
	do shell script "/usr/bin/SetFile -d " & (quoted form of d) & " " & t
end setcreationDate

Exactly! I love the script you wrote to sync iphoto dates with file system creation dates. I’ll use that! Thanks Jacques. :slight_smile:

Jacques , your iPhoto script doesn’t compile. There’s a problem with “original path”. I’m using iphoto 7.1.5 and looking at the properties of a photo here’s what I get.

Note there’s no original path!

I’ll just remove the “if” statement in the setcreationDate subroutine, then remove the orginal path variable all together, but I wanted to let you know.

That’s cool! Now it’s working. I did the 3-day period and looking at the found images brings back great memories. Awesome. :smiley: