Copy Item Link of Parent Group?

Often I will be reading/browsing an item in DT3 and I want to copy the item link not of that particular document but rather of the group the document is in, i.e. the parent group.

Is there any quick way to do this without backing up to the group, copying the group item link, and then going back to the specific document at hand?

Only by using a script.

1 Like

Good moment to ask this question (I stumbled upon it about some days ago):

How do I know which the parent group is? Thereā€™s a parents list in the record structure, but that can of course contain more than one element. I suppose that is needed for replicants so that the parents list contains all the groups where this record is replicated to. So how would one go about to find the parent group of a record?

Applescript
set theParent to parent 1 of theRecord
edit; @BLUEFROG & @Pete31 report the problems with this code

edit; Iā€™ve somehow ended up with a tag as Parent 1
Iā€™ll need to walk through the parent list to bypass tag parents

Actually that would be incorrect.
That would only report the first parent of a replicated item. That wouldnā€™t accuratley reflect the current parent.

1 Like

Correct - an item will have more than one parent when itā€™s replicated.

The parents show the parent of first addition of the item listed first.

Also, parents will show /Tags/ - and things akin to "/Tags/DEVONthink/" with hierarchicial tags - as a parent for tagged files.

The order changes if the first parent has been moved between script runs.

1 Like

Noting @cgrunenberg would have to assess the need and feasibility of modifying the parent and location properties for replicants (and it likely isnā€™t a trivial matter), here is a core approach that could be usedā€¦

tell application id "DNtp"
	set sel to selection
	if sel ā‰  {} then
		set selectedItem to item 1 of (selection as list)
		set currGroup to {location, name} of current group -- Containing group of the selected file
		-- You cannot use the location of a replicated file as it's location is the same as the original parent
		
		-- Process the parents of the selected file
		tell selectedItem
			set possibleParents to parents whose location does not start with "/Tags/" -- Ignore parents in Tags
			
			repeat with currentPossibility in possibleParents
				set currentPossibilityIsWhere to {location, name} of currentPossibility -- Get the location and name of each parent in turn
				
				-- Logging for debugging as this can be a tricky thing to suss out. Comment out as needed
				log (currentPossibilityIsWhere as string)
				log (currentPossibilityIsWhere & "/" as string = (currGroup & "/" as string)) -- Note appended "/" is required for an = match. I suggest this form.
				
				if (currentPossibilityIsWhere & "/" as string = (currGroup & "/" as string)) then
					
					-- Another log for debugging to verify the correct item link is reported
					log (reference URL of currentPossibility as string)
					
					-- Do whatever with the info
					set parentURL to (reference URL of currentPossibility)
					exit repeat -- Stop processing as the current parent has been matched with the current location
					
				end if
			end repeat
		end tell
		create record with {URL:parentURL, type:bookmark} in incoming group
	end if
end tell
1 Like

Every replicated item has multiple parents but thereā€™s no such thing like an original item nor a dedicated/primary/preferred parent group.

Sure, what I meant is: If youā€™re using item 1 of parents of theRecord in a script be aware that if you move the group (that was parent 1) between script runs youā€™ll get another group with item 1 of parents of theRecord.

Good thing thereā€™s no need to get parent 1 in this situationšŸ˜‰

Re the script:
If I understand that correctly, youā€™re using the location property of current group to figure the parent group of the first element of the current selection. Also, if I understand correctly, current group refers to the (currently selected) group of the front most window of the currently selected database. You then compare the location of the recordā€™s parent(s) to the location of the current group (basically, I didnā€™t see name used).
Given these premises (which might be false, of course): If I select two records in two different groups

  • which of those is the first in the list?
  • what is current group in this case?
  • would it be possible that the first record belongs to a group that is not the current group?

You are understanding my approach to the issue.

Outside of adding an error trap to check for only one file being selected, the script is intended for getting the item link of a selected file, not multiple selected files.

I see, that makes it clearer.

Good deal!

PS: While I didnā€™t formally error-trap by counting the selection, I indirectly did it viaā€¦

set selectedItem to item 1 of (selection as list)

:slight_smile:

selection as list looks kind of thorough, since selection is a list already (or isnā€™t it?) Or did you use that just on educational purpose?

This whole parent(s) thing is a bit unfortunate, I think. Only replicated records can have more than one parent group, right? So if count of the record's parents is > 1, it is replicated? And only in this case does one have to go through the callisthenics with current group.

Still assuming that all this is correct, wouldnā€™t it be simpler to have a single parent property referencing the parent group? Thereā€™s a separate replica property, and what does one need the list of all parents for a record for?

selection as list looks kind of thorough, since selection is a list already (or isnā€™t it?) Or did you use that just on educational purpose?

Actually a selection is not a list.

Try this and youā€™ll see the errorā€¦

tell application id "DNtp"
	class of selection
end tell

Actually, (selection as list) is a bit of muscle memory.
The following construct is less obvious but does the same thingā€¦

tell application id "DNtp"
	item 1 of {selection}
end tell

(selected records) can also be used, however I use that when querying specific properties of a selection.

tell application id "DNtp"
	name of (selected records)
end tell

Those are questions only @cgrunenberg could authoritatively answer :slight_smile:

OK - well so much for my hope to address my initial question by writing a script - this is a bit more complex than I realized.

If anyone is successful in writing a script to ā€œget parent item linkā€ I would be interested.