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.
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.
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.
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.
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)
It must do, yes. That’s shame 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.
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.
move the resulting Smart Group into the Navigation Sidebar’s Smart Rule section
add action Execute Script in the resulting Smart Rule
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
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!