Deleting all replicants but one?

Hi all-

I’d like to write a script that deletes all the replicants of a file, but leaves the database item in its current location.

I assume that deleting a replicant is accomplished by deleting a parent item?

Further, it seems that the location of the database item is always returned as item 1 of the parents list. Is this guaranteed, which would greatly simplify scripting, or do I need to iterate through the parent list and find the one that matches the item’s location?

Thanks in advance!


The only difference between a replicant and other items is that a replicant has multiple parents. Therefore all you have to do is to remove the replicants from all parents except the first one.

How is that true when all replicants for a single document are in the same group?

In this case the replicant has also multiple parents but the parents are the same.

Got it. A replicant has multiple parents that are different and/or the same.

@sjk: Would you mind sharing the code?

There’s no code to share, only my understanding of Christian’s explanation of multiple parents for replicants.

Not quite a DeleteAllReplicantsButOne(this_record, keepInThisGroup) function, but it might be helpful for writing it.

Update: a dialogue based version is here:

--Checks if record is already replicated to specific group
--expects: record and group as objects; returns boolean
on RecordHasReplicaInGroup(myRecord, myGroup)
	log ">>>> RecordHasReplicaInGroup"
	set hasReplicaHere to false
	tell application "DEVONthink Pro"
		-- Is DT record at top level?
		if exists parent 1 of myRecord then
			-- loop through parents of DT record
			set parents_count to (count parents of myRecord)
			repeat with i from 1 to parents_count
				set parent_group to item i of (parents of myRecord)
				if myGroup is parent_group then set hasReplicaHere to true
			end repeat
		end if
	end tell
	log ">> RecordHasReplicaInGroup returns: " & hasReplicaHere
	return hasReplicaHere
end RecordHasReplicaInGroup

I’m still too AppleScript-unsavvy to understand exactly what it does, though it inspired me to wonder how upcoming replicant-based tags and UI related changes might influence replicant management in general and possibly “solve” some of the existing issues as a side effect.