Smart Rule: Remove Replicant

I want to delete one replicant with a smart rule (the equivalant to manually select a replicant and press “Backspace”). There doesn’t seem to be a matching action. I tried “Move to Trash”, but it deletes all instances/replicants.

Is there a way to achieve this?

This isn’t supported currently but might be in future releases. How would the workflow actually look like?

I have a group where I store replicants of items, which I want to “proceed”. These are mainly texts, PDFs and web links. After I’m done with an item I set its color label to green. I would like to have an automatic routine which removes these replicants with a green label after some days (a kind of clean up).

So basically you use the replicants as a way to flag items which still need to be processed? A workaround might be to use a flag, rating, label, tag or custom metadata instead of replicating.

Please post the smart rule you are/were using as a screenshot

Is there a reason you first want to manually set them to green and not trash the replicate by hand immediately when you’re done?

Both are manual steps that appear to limit any automatic steps that follow.

The “after some days” bit might be relevant there; seeing not only what has to be done, but also what has already been done can be useful in my opinion.

1 Like

I should have mentioned that the reason for an additional group and the replicants is DTTG. The group is set to “always sync” on my mobile devices, so I have all its items locally without the need to download them first.

I would like to keep the possibility to “go back” to an item. Also items may be related to the same topic and therefore I want to proceed them together.

so, here’s a workaround:

on performSmartRule(theRecords)
	tell application id "DNtp"
		try
			repeat with theRecord in theRecords
				set theDatabase to database of theRecord
				set theName to name of theRecord
				set theFile to duplicate record theRecord to parent 1 of theRecord
				move record theRecord to trash group of theDatabase
				set name of theFile to theName
				set label of theFile to 0
			end repeat
		on error
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
			return
		end try
	end tell
end performSmartRule

That script first duplicates the record in the group of the original, then moves the replicant to trash (which, as you pointed out, moves all replicant instances to trash), then renames the duplicate to remove the word “copy” from the end of the file name. It then removes the green label.

I’ve run the script from a smart rule which looks like this:

On my tests this works as I have understood you to want it. Please test on some test files before using; note that the script does not itself limit the type of files it works on - it relies on a smart rule to pass it the right files.

You have a number of possibilities re. “delete after a few days”; you could use an “on label” action in a smart rule script to copy the date + 5 days on which the record was marked green to custom metadata (which I’ll call “Greened” here), and then add a condition to the above rule called “Greened is within last 1000 days”

The appropriate script for adding to the metadata (again, assuming you have set up custom metadata called “Greened” - change that as you see fit) would be

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			if label of theRecord is 2 then
				set expiry to current date
				# added expiry is in seconds
				set expiry to expiry + (60 * 60 * 24 * 5)
				add custom meta data expiry for "Greened" to theRecord
			else
				add custom meta data 0 for "Greened" to theRecord
			end if
		end repeat
	end tell
end performSmartRule

That script would be triggered by a rule like this:

(I’m AFK, but I’ve just realised the second script needs an if label is green condition, I’ll add that when I’m back → done; metadata is added if label is green and removed if label is anything other than green; again, this script does not select which documents to work on - it relies on a smart rule to send it the right records)

2 Likes

Your help and time you put into this is very much appreciated.

Correct me if I’m wrong: If you duplicate the item the copy gets a new item link. This would be a showstopper for me.

1 Like

It must do, yes. That’s shame :confused: I’ve not come up with any other solution; I’m sorry. The replicant is treated as the original by scripts and rules, unless Ive missed something this is something only DT can solve.

I know it’s been a while but your workaround saved my day and helped do sort out some mess I’d made with my database. Many, many thanks. :pray: :bowing_man:

3 Likes

Welcome @Hlgr and thanks for the nice follow-up.
:slight_smile:

1 Like

That’s excellent news, thanks for coming here to let me know :slight_smile:

Just to add that I would also like to be able to remove replicants programatically (via AppleScript).

My current use case is also a workaround for DTTG (plus Shortcuts). Because there is currently (as far as I’m aware) no way to list items by their label from within a shortcut, the workaround is for DEVONthink desktop to replicate the required items to a group. The problem, then, is that these replicants cannot be removed automatically when needed.

A smart rule which searches only in this group for replicated items could move the found items to the trash. NOTE: The search scope is important so that not all replicants are removed.

You could try this script.

If it does what you’re looking for you could try to

This should work, I think. Please try with duplicates.

-- Remove replicants

on run
	tell application id "DNtp" to my performSmartRule(selection as list)
end run

on performSmartRule(theRecords)
	tell application id "DNtp"
		try
			repeat with thisRecord in theRecords
				set thisRecord_Type to (type of thisRecord) as string
				if thisRecord_Type is in {"group", "«constant ****DTgr»"} then
					set thisRecord_Children to (children of thisRecord whose number of replicants > 0)
					set thisRecord_Database_TrashGroup to trash group of (database of thisRecord)
					
					repeat with thisChild in thisRecord_Children
						set thisChild_LocationGroup to location group of thisChild
						if thisChild_LocationGroup ≠ thisRecord then
							move record thisChild from thisRecord to thisRecord_Database_TrashGroup
						end if
					end repeat
					
				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
			return
		end try
	end tell
end performSmartRule


Thank you very much. I will try it out.

I had the same need — automatically to remove replicants — but nothing happened when I ran this script with a replicant selected.
EDIT:
This is a smart rule to find replicants, but none appears.



EDIT:
OK, I was wrong. The replicants did disappear (which is why they did not show up in the smart group). It just took a while to happen. Seriously, immediately after running the script, the replicants were all just sitting there. Thanks to all!