Smart Group Script - Today, This Month, Last Month, etc...

I would love to get a hold of a few more DT scripts that create smart folders that display all documents added/created in preset periods of time…DT comes with one such script called “Last Week”, but I was hoping someone might be able to give me a hand and provide me with similar scripts that create smart groups for:

-Today
-This Week
-Last Week
-This Month
-Last Month
-Last 3 Months

I know that you can simply use either the History or Search functions to achieve basically the same thing, but I was hoping to be able to have 1-click access to the time periods listed above…

Any help would be greatly appreciated. Thanks!

It’s really easy: All you have to do is to copy the script (~/Library/Application Support/DEVONthink Pro/Smart Group/CLast Week.scpt) and to modify the search age and the name.

can you give me one example…perhaps one that would create a smart group of documents created in the last 1 month? If I can get one example and compare it with the existing script, I will easily be able to do the rest, but I know myself and without it, I am bound to messing things up for a while before finally getting it right…

Thanks!

Just replace…

  • “Last Week” with “Last Month”
  • 3600247 with 36002431

Got it…thanks for baby stepping me through that. I do appreciate it!

What about doing one for “This Month”, and a separate one for “Last Month”…

Wouldn’t a script like that have to be configured slightly differently, by adding some sort of a qualifier that disallows anything added in the last 30 days, but permits things added between 31 days ago and 60 days ago?

The following code calculates the seconds of this month. Just use this as the desired time interval and you’ll get a “This Month” smart group.


set theDate to current date
set theSeconds to (day of theDate) * 24 * 3600
set theSeconds to theSeconds + (hours of theDate) * 3600
set theSeconds to theSeconds + (minutes of theDate) * 60
set theSeconds to theSeconds + (seconds of theDate)

Can you please let me know how I am supposed to insert that code into the existing script to make it work…I’ve tried figuring it out on my own, but haven’t been successful…

Here is the script I am trying to place the code you provided into:

on run
	try
		set scriptPath to POSIX path of (path to me)
		if scriptPath ends with "/" then set scriptPath to ""
		tell application "DEVONthink Pro"
			my triggered(create record with {name:"Last Month", type:group, attached script:scriptPath})
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end run

on triggered(theRecord)
	try
		tell application "DEVONthink Pro"
			if type of theRecord is group then search age (3600 * 24 * 31) replicate to theRecord with removing replicants
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end triggered

can you please reply back with the correct placement and formatting of the code you provided…Thanks so much for your help!

Insert it before…


     tell application "DEVONthink Pro"
         if type of theRecord is group then search age (3600 * 24 * 31) replicate to theRecord with removing replicants
      end tell

…and then replace “3600 * 24 * 31” with theSeconds.

ok look…I am a complete moron when it comes to AppleScripting…can you please just do me a huge favor and respond back with the entire script from start to finish, just as it should be so that I can copy and paste it into the script editor and then simply press ‘Save’?

I am sorry to ask for such a blatant hand out…but I have no other choice at this point, as I am still as lost as ever…

Thanks, and please forgive my ignorance!

This should work:


on run
   try
      set scriptPath to POSIX path of (path to me)
      if scriptPath ends with "/" then set scriptPath to ""
      tell application "DEVONthink Pro"
         my triggered(create record with {name:"This Month", type:group, attached script:scriptPath})
      end tell
   on error error_message number error_number
      if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
   end try
end run

on triggered(theRecord)
   try
	set theDate to current date
	set theSeconds to (day of theDate) * 24 * 3600
	set theSeconds to theSeconds + (hours of theDate) * 3600
	set theSeconds to theSeconds + (minutes of theDate) * 60
	set theSeconds to theSeconds + (seconds of theDate)
      tell application "DEVONthink Pro"
         if type of theRecord is group then search age (theSeconds) replicate to theRecord with removing replicants
      end tell
   on error error_message number error_number
      if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
   end try
end triggered

Thanks so much…I really appreciate your help!

I’m looking to do something similar to the above (modified before yesterday) etc on DT2.03, but the SmartGroups are now stored as a .plist file with an (encrypted?) pointer to somewhere else. Are we able to modify the scripts in smartgroup scripts in DT2.03? Thanks.

Post followups: here

… to your similar post/question?

Yes, to my similar question there. From a review of the forum threads it appears that appending to the end of an “old” thread has a much slimmer chance of someone (that can add value) taking a look. If I have caused an offense by posting in two locations, my apologies.

No offense, only …

My opinion is that multi-posting often isn’t reader/respondent-friendly. For example, it took extra time reading both your posts and I’d have to randomly choose one if I was going to respond, while other respondents could choose the other and fragment the topic. As an alternative to multi-posting I’d only create one “master” post, then link to it in other spot I’m interested in it getting people’s attention with a mention of preferring followups directly to the master post.

So, my “Post followups” reply/link here was an attempt to designate your other post the “master” and suggest followups be directed there. Sorry if my helpful (and too subtle?) intention was interfering to you, though hopefully you understand it now. :slight_smile:

Anyone have any ideas on this issue? Again, it appears that the previous version of DT stored smart groups as modifiable text files, where the current version stored info in a .plist. Any way to make a smart group for a range of dates, etc? Thanks