Smart rule Date not Found

Hey there!

I couldn’t find a fitting thread, so I’m starting a new one:

I really like the Smart rule feature. However, I’m trying to change the document name to the document date but if there is no document date found, I’d like to insert todays date. Is there any option to do this? As far as I can see, there is no way to set a condition such as “document date exists”… Anyone able to help?

Cheers!

Is there really no date in the document or is it just not found?

This is not possible without scripting.

Bear in mind there may be more than one possible document date detected.

Here is a teaching edition snippet regarding date detection. The results can be used for stringing the parts together or used independently, e.g., used as Tags, etc.


tell application id "DNtp"
	repeat with thisRecord in (selection as list)
		set possibleDates to all document dates of thisRecord
		
		-- Choose the oldest or newest date
		if (count possibleDates) > 1 then
			set docDate to oldest document date of thisRecord
			-- set docDate to newest document date of thisRecord
		else -- Or accept the only possible date
			set docDate to item 1 of possibleDates
		end if
		
		-- Process date 
		set dateYear to year of docDate
		
		set dateMonth to month of docDate as integer
		if dateMonth < 10 then set dateMonth to ("0" & dateMonth)
		
		set dateDay to day of docDate
		if dateDay < 10 then set dateDay to ("0" & dateDay)
		
		-- Create a new date string
		set dateString to (dateYear & dateMonth & dateDay) as string
		
	end repeat
end tell

This could be added in an Execute Script action in a smart rule, however, you’d need to make sure your smart rule is targeting the appropriate files to process (which you should be doing with any smart rule).

@BLUEFROG I’ll try this, thank you!

@cgrunenberg I’m applying this to a scanned receipt. There is a date in the document, but it’s not always found since the quality of the receipt varies.

Could you send some poor example scans to cgrunenberg - at - devon-technologies.com? Maybe it’s possible to improve the recognition. Thanks!