Replicants, instances of

Appreciating that Replicants are only ever one copy of a file or folder, what’s the (best) way to find within DT 3 where all instances of a Replicant live, please… i.e the parent Group of each?

Am trying to streamline my use of Replicants.


This script reveals a replicant in the selected parent group.

If you just want to see the parent groups’ locations run the script and cancel the dialog.

-- Reveal replicant in parent group

tell application id "DNtp"
		set theRecords to selected records
		if theRecords = {} or (count theRecords) > 1 then error "Please select a record"
		set thisRecord to item 1 of theRecords
		if (number of replicants of thisRecord) > 0 then
			set theParents_Names to name of parents of thisRecord whose location does not start with "/Tags/"
			set theParents_Locations to location of parents of thisRecord whose location does not start with "/Tags/"
			set theParents_UUIDs to uuid of parents of thisRecord whose location does not start with "/Tags/"
			set theParentsCount to count theParents_Locations
			set theParents_LocationsAndNames to {}
			repeat with i from 1 to theParentsCount
				set thisParent_Name to item i of theParents_Names
				if thisParent_Name contains "/" then set thisParent_Name to my escapeSlash(thisParent_Name)
				set end of theParents_LocationsAndNames to ((item i of theParents_Locations) & thisParent_Name & linefeed & item i of theParents_UUIDs) as string
			end repeat
			if theParentsCount > 2 then
				set theParents_LocationsAndNames to {item 1 of theParents_LocationsAndNames} & my sort_list(items 2 thru -1 in theParents_LocationsAndNames)
			end if
			set chooseFromListItems to theParents_LocationsAndNames
			set theChoice to choose from list chooseFromListItems with prompt "" default items (item 1 of chooseFromListItems) with title "Replicant Parents" with multiple selections allowed
			if theChoice is false then return
			set theChoice_Count to (count theChoice)
			if theChoice_Count = 1 then
				set thisParent to (get record with uuid (paragraph 2 of (item 1 of theChoice)))
				if class of think window 1 = viewer window then
					set theWindow to think window 1
					set root of theWindow to thisParent
					set theWindow to open window for record thisParent with force
				end if
				set selection of theWindow to {thisRecord}
				repeat with i from 1 to theChoice_Count
					set thisParent to (get record with uuid (paragraph 2 of (item i of theChoice)))
					set theWindow to open window for record thisParent with force
					set selection of theWindow to {thisRecord}
				end repeat
			end if
		end if
	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

on escapeSlash(theText)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "/"
	set theTextItems to every text item of theText
	set AppleScript's text item delimiters to "\\/"
	set theText_escaped to theTextItems as string
	set AppleScript's text item delimiters to d
	return theText_escaped
end escapeSlash

on sort_list(theList)
	considering numeric strings
		set theIndexList to {}
		set theSortedList to {}
		repeat (length of theList) times
			set theLowItem to ""
			repeat with a from 1 to (length of theList)
				if a is not in theIndexList then
					set theCurrentItem to item a of theList as text
					if theLowItem is "" then
						set theLowItem to theCurrentItem
						set theLowItemIndex to a
					else if theCurrentItem comes before theLowItem then
						set theLowItem to theCurrentItem
						set theLowItemIndex to a
					end if
				end if
			end repeat
			set end of theSortedList to theLowItem
			set end of theIndexList to theLowItemIndex
		end repeat
	end considering
	return theSortedList
end sort_list

1 Like


tell application id "DNtp"
	set sel to (item 1 of (selected records))
	set parentRecords to ((parents of sel) whose location does not start with "/Tags")
	if (count parentRecords) > 1 then
		set parentList to {"# " & (name of sel as string) & " replicated in…" & linefeed}
		repeat with thisParent in parentRecords
			set loc to ({location, name} of thisParent)
			copy ("- " & (loc as string) & "  " & linefeed) to end of parentList
		end repeat
		set parentDoc to create record with {name:(name of sel as string) & " Replicants", type:markdown, source:parentList as string} in current group
		set selection of think window 1 to {parentDoc}
		display alert "This document has only one parent so it cannot be a replicant."
	end if
end tell


1 Like

Peter, Jim - thanks so much. Shall try and post here again :slight_smile:

Your quick help very much appreciated!

Thanks, @pete31 !

I placed the script in ~/Library/Application Scripts/com.devon-technologies.think3/Menu/Data

But when I had a Group which I know to be a Replicant highlighted, the script returned ‘Please select a record’. My apologies if I wasn’t clear that I hoped to find a way to reveal Groups which are Replicants.

Thanks, Jim - not sure what I’m doing wrong.

I placed the script in ~/Library/Application Scripts/com.devon-technologies.think3/Menu/Data

But nothing happens when I run it - except those cases where the doc does indeed have no parent and so cannot be a Replicant, when I did get that message.

Perhaps it’s not possible to identify and flag Groups as such?

This error message is only displayed if there’s either 0 or more than 1 record selected. So if you select one record (or group) it should work.

(It’s funny as I normally use different error messages if 0 or more than 1 records are selected: „Please select a record“ vs. „Please select only one record“. In this script I didn’t do that …)


Thanks. Tried again. I have a (DT) Group containing docs for Apple Books (the app).

It’s in my Computer > Software folder: in two places:

  1. Software > Apple Media apps
  2. Software > Texts

When I select the replicated Group (italicized in red) in either location then call your script (thanks again!) from the Data scripts subfolder, I get that message.

When I select a document in the Group (italicized in red) in either location (which is of course less helpful: I’m hoping to be able to locate both replicated Groups in their respective hierarchies), I get nothing.

It doesn’t make a difference whether you select a group or a record, for DEVONthink’s AppleScript they are both a record.

I now ran the script as posted above from DEVONthink’s script menu with a group selected and it works.

No idea why it doesn’t work for you. Could you post a screenshot of your selection and the error message?

Of course. Thanks again!

I’d also say that the structure in your own screengrab is more or less what I have.

Just to be clear:

  1. I copied the text of your script into BBEdit
  2. gave it a title (Peter Reveal replicant.scpt); and resaved it
  3. compiled it (without errors) in Script Editor
  4. copied it to ~/Library/Application Scripts/com.devon-technologies.think3/Menu/Data

and have been running it from within DT 3.

I have little doubt that the error is mine :slight_smile: !

You need to select a record in the item list, not in the navigation sidebar :slight_smile:

If an AppleScript contains selected records then it always means that one has to use the item list (or one of the other views).

(Sometimes it’s necessary to use the selection of the navigation sidebar in a script, but if that’s the case then I mention that (because it’s not the “default”)

1 Like

Ahhh, got it: the script doesn’t give any feedback if the selected record is not replicated, it just quits.

This means you selected a non-replicated record inside a replicated group. With this setup you’re seeing each child record in two (or more) places in your database, but the child records themselves are not replicated, only the parent group is replicated.

If a record is replicated then there’s a little icon behind the record’s name.

1 Like


As I thought: your script works as planned :slight_smile:

But I put that folder (‘Accompanying PDFs…’) and that file (‘Audible books not…’) in one Group (‘Apple Media Apps’) and they immediately and automatically appeared in the other (‘Books’) by themselves.

So I must still not really understand how Replicants work, I’d say.

Can only parents (Groups with children) be replicated - and their children inside those (Replicated) Groups not?

Thanks, @DTLow - what I want to be able to do is see where every instance of a replicated Group is in any/all possible parts of the database hierarchy.

I am almost ashamed to say that for some Replicants I created I failed to keep a record of where the Replicant is.

For instance, I have a Group at root level in the one DT database I have called ‘Finance’.

Under Finance I have several subgroups (none replicated) for bank statements. In that I also have statements that are for investments, not strictly banks as such. But investments.

Under ‘Finance’ I also have a Group called ‘Investments’.

I have replicated the subGroup for bank statements for investments in the subGroup for investments under Finance.

No matter whether I try to find monthly investment statements under ‘Bank’ or ‘Investments’ I shall find them.

Am I perhaps misusing DT Replication?

This post should make it clear

1 Like

Thanks again, @pete31!

Although I couldn’t find it here on the forum, I did get an explanation from you by email explaining that I need to select the record in the item list, not in the Sidebar.

Now it works perfectly.

Extremely useful! Much appreciated :slight_smile: .

1 Like

Update: Jim, when I select a record in the Item list - as pete31 kindly pointed out - your script works perfectly.


1 Like

Indeed! The item list and Navigate sidebar do not behave the same in some ways, including reporting selections to scripts.
Glad to hear it though.

1 Like