Useful smart rule examples

I have been hesitant about starting this thread, concerned that it might seem a little presumptuous. However, I did think it could be interesting for people to collate examples of useful smart rules in one thread so I have taken the plunge. This example has previously been posted in another thread, so apologies for repeating it to start this thread.

The purpose of this rule is simple. It identifies a bank statement downloaded to the global inbox (I have redacted personal information in one field) and files it by year in the appropriate DT3 folder.

I hope others will feel able to contribute smart rules which they have found useful.



In these threads are more examples:


Many thanks for collating those cross-references.


Apologies for contributing to my own thread but here is one more smart rule which I’ve found very useful. It identifies all indexed items (as opposed to items specifically included in a database) in all open databases.


Wouldn’t a smart group be sufficient for this case?

<Sigh> You are of course correct (as ever!). It’s my fault for not really appreciating that a smart group could be independent of a specific database (I thought in cases like this you had to replicate the smart group in each database.)

To be clear, this is much better as a smart group than as a smart rule. <Departs with tail between legs>


1 Like

Actually, smart groups and smart rules can be exported and imported. Check out the contextual menu.


They can be importing via the command or merely double-clicking the .dtSmartGroup or .dtSmartRule file in the Finder.

Sorry. Wasn’t paying attention.

1 Like

No worries. :slight_smile:

Is it possible to create and synchronize Smart Rules within a database (group)? So far I haven’t found a way to avoid having to redefine the Smart Rules in the sidebar on every computer.
This is not only annoying, but also error-prone.

This may help (from the user guide—also available in app):

Smart rules can be exported to the Finder, sent by email, and e.g., reimported to DEVONthink on another Mac. Drag a smart rule to the desktop to save it to a file or Control-click it and choose Export. Double- click a saved smart rule to import it, drag it into the sidebar, or Control-click into the sidebar and choose Import.

Edit: sorry—see also this post earlier in the thread.


1 Like

Could you please describe the differences / different use cases for Smart Rules and Smart Groups?
Thx, Marko

Thanks @Stephen_C for starting this thread! Very useful.

This smart rule will clean up the formatting of clipped articles (when they are clipped as clutter-free RTF). The default fonts and formatting for clipped RTFs is too large for my taste, so I made this combination of smart rule and script to make them match my personal defaults.

My simplified differentiation: a Smart Group is a saved search that allows you to view a set of items that meet what can be a complex selection criteria, all in one list. A Smart Rule extends that concept by allowing you to take one or more actions on those selected items.

Find some items to view in one place: Smart Group.
Do something with or to those items: Smart Rule.

No. Smart rules are global, not local. You can control-click and export them and import them in DEVONthink on another account or machine.

Just because you match files in a smart group, you don’t have to act on them.
If you have files you want to match but also act on them, use a smart rule.

Use cases would vary, but here is an example of a smart rule in the Help > Documentation > Automation > Smart Rules section…

Thank for this hint…
I realize I need a certificate course to use the help. :slight_smile:
Common sense and common procedures (aka Spotlight) are not sufficient for the use of DTP3.

DTP3 has a wonderful built-in search (or better “find”) function. Why don’t you use it yourself?

I like to file my documents with filenames that include the date of the document, often taken from the document itself (not the date that document was imported to DevonThink), such as “YYYY-MM-DD document title.pdf”. My ScanSnap scanner can do that automatically, but if I’m sourcing a file from elsewhere, I need to add the date and change the name to something appropriate. This smart rule does that, and can be run on demand by right-clicking an imported file in the Inbox and selecting the rule.

1 Like

One more way to think about Smart Rules. You can see it as actions with selective scope, which is limited to the items you define in search terms. So, if you select any items in any groups altogether and apply this rule on them - it will act only on those items, which are in its scope and currently selected. The rest will stay untouched.

Selecting all items in all databases and choosing “Apply” is the equivalent of “Perform” the rule

This smart rule adds 2 spaces at the end of every Markdown line

While not required, I recommend including two spaces at the end of each line of metadata. In this way, if you pass your document through a regular version of Markdown, the metadata will be properly formatted as plain text with line breaks, rather than joined into a single run-on paragraph (

-- Add 2 spaces at the end of every MultiMarkdown line (as recommmend

on performSmartRule(theRecords)
	tell application id "DNtp"
			repeat with thisRecord in theRecords
				if type of thisRecord = markdown then
					set theText to plain text of thisRecord
					set theParagraphs to paragraphs of theText
					set newText to ""
					repeat with thisParagraph in theParagraphs
						set thisParagraph to thisParagraph as string
						if thisParagraph is not in {"", "---"} then
							if thisParagraph does not end with "  " then
								set thisParagraph to thisParagraph & "  "
							end if
						end if
						set newText to newText & thisParagraph & return
					end repeat
					set plain text of thisRecord to newText
				end if
			end repeat
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		end try
	end tell
end performSmartRule


I’ve set it to run “After Saving” but am not sure if this is optimal as (I think) it runs on all markdown files every time I save a markdown record.

(Also tried to use custom metadata to filter all records that the smart rule already ran on, but this way it was only applied once and didn’t add spaces if a record was changed.)

Is it a problem to set it to “After saving” when no other conditions are used?

DEVONthink’s help already answered this:

On Save: Runs when any matching document is saved.

1 Like