SMART rule to date imported email

I’ve created a smart rule to date an imported email with the creation date. To ensure correct sorting the format I want to use is YY-MM-DD - Subject

It’s all working, but I can’t see an option for short year (YY)?

There’s no such option, only one for YYYY.

Is there an alternative way?

Only via scripting.

Do you have an example script you could share?

There are tons of examples of AppleScript date handling in the forums, but here’s a quickie in a more explanatory style…

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set cD to (creation date of theRecord)
			set mm to my zeroPad(month of cD as integer)
			set dd to my zeroPad(day of cD)
			set yy to my zeroPad((characters 1 thru 2 of (year of cD as string) as string))
			set name of theRecord to (yy & "-" & mm & "-" & dd & " " & (name of theRecord))
		end repeat
	end tell
end performSmartRule

on zeroPad(theNum) -- Add prefixing zero
	if theNum ≥ 10 then return (theNum as string)
	return ("0" & theNum as string)
end zeroPad
2 Likes

Thank you

No problem.
Do you understand what’s going on there?

Yes, thank you - I’ve already used it as a basis for other scripts…

Excellent :slight_smile: