Automate creation of daily (date ranged) Smart Groups

Hey gang!

I’m hoping someone has a script, workflow, template or advice to speed up what is currently a manual (and long) process.

What I’m trying to do

Automate the creation of Smart Groups for the entire year with months (as Groups) and days (as Smart groups) similar to Template » Registers » 1-31 but with the search criteria for each day already inbuilt.

For example:

2021 (Group)
09 September (Nested Group)

  • 2021-09-01 (Smart Group)
  • 2021-09-02 (Smart Group)
  • 2021-09-30 (Smart Group)

If there is no way to automate this process, if anyone has a link to a Custom template that has already been setup by another user and shared, I’d be very grateful.

Thank you all for your help in advance!

It’s not yet possible to script global smart groups (the ones in the sidebar), only local smart groups inside databases would be possible that way. E.g. here’s a basic example:

property pMonths : {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
property pDays : {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

tell application id "DNtp"
	set theGroup to current group
	repeat with m from 1 to 12
		set theMonthName to (m as string) -- item i of pMonths
		set theMonthGroup to create record with {name:theMonthName, type:group} in theGroup
		set theMonthQuery to "2021-" & (m as string) & "-"
		set numDays to item m of pDays
		repeat with d from 1 to numDays
			set theDayQuery to theMonthQuery & (d as string)
			set theDayBeginQuery to "modificationDate>=" & theDayQuery & " 00:00:00"
			set theDayEndQuery to "modificationDate<=" & theDayQuery & " 23:59:59"
			set theQuery to theDayBeginQuery & " " & theDayEndQuery
			create record with {name:(d as string), type:smart group, search predicates:theQuery} in theMonthGroup
		end repeat
	end repeat
end tell

However, I wonder whether so many smart groups are actually necessary/useful. Did you have a look at Tools > Filter > Info and the possibility to limit the current main view to items with a certain date or in a date range? Filters can be also applied to global smart groups or search results.

Thank you for this script and for the further advice. I’ll have a play around with both options.

The reason behind using Smart Groups is primarily to shortcut the act of searching. I have data stored in contextual groups within a single database, but when I want a quick overview of everything I might have been reading, writing or researching on that day, week or month, I can quickly navigate to the parent group (say March 2021) and expand all the contained Smart Groups to quickly see an aggregation of those documents. This helps me to visually track and place my thought process within context to that period of time (how an image saved and stored in one group might have inspired a note stored in another group or aided further research stored as a pdf in another group).

I’m not very proficient as yet with the advanced search options, so for me, Smart Groups keeps things accessible and easy to find.

Thank you again for your help! Really appreciate it! :grinning: :+1:

The script works great! Thank you :grinning:

I have been able to figure out how to change the year set theMonthQuery to "2021-" & (m as string) & "-" by replacing 2021 with my required year, and changing modificationDate to creationDate. A huge deal for me and I’m still learning! :raised_hands:

But I can’t figure out how to add three more search criteria’s – exclude groups, tags and smart groups.

I’d be grateful for any advice! Thank you again for your help!!

1 Like

The easiest way to figure out the right search syntax is to set up an advanced search via the user interface. The search term in the toolbar gets automatically updated. In this case just append kind:any

Thanks for the help! Following your instructions I have the following:

kind:tag
kind:group
kind:smart group

But how do I actually write this in the script to translate as kind is not tag, kind is not group and kind is not smart group?

I’m guessing it has something to do with `set’

set theKindQuery to (is not) tag ?

I’m kinda lost with what I need to do. Could you provide me with an example to follow please?

Actually you don’t need these conditions, kind:any is sufficient:

set theQuery to theQuery & " kind:any"

This limits results to documents.

That works great! Thank you so much for your help! :raised_hands: