Importing and exporting tags

Is there a way to export tags, but without the documents that are tagged by those tags? In other words is there a way to export only the tags as tags, and import them into another DTP file?

I ask because I have a mega central DTP database, but I also gather data into some smaller databases, and tag that data before exporting it into the central database. I have set up a pretty complex hierarchy of nested tags that acts as a mega index to my content. When I am tagging files in one of my smaller databases it would be useful to have the same hierarchy of tags in that file so that I don’t unnecessarily duplicate tags, or have to refer backwards and forwards between databases to recall what tags I used.

If there IS a way to export and import tags, it would be great to know it. If not, is it something you could add to a future release.

You could use this script to duplicate a hierarchy without its documents:



-- Duplicate hierarchy

tell application id "com.devon-technologies.thinkpro2"
	try
		set theNum to my duplicateGroups(the selection, incoming group of current database, " copy")
		if theNum is 0 then error "Please select one or more groups."
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

on duplicateGroups(theRecords, theDestination, theSuffix)
	local theRecord, theName, theCopy, theNum
	set theNum to 0
	tell application id "com.devon-technologies.thinkpro2"
		repeat with theRecord in theRecords
			if type of theRecord is group then
				set theName to ((name of theRecord) as string) & theSuffix
				set theCopy to create record with {name:theName, type:group} in theDestination
				set theNum to theNum + (my duplicateGroups(children of theRecord, theCopy, "")) + 1
			end if
		end repeat
	end tell
	return theNum
end duplicateGroups

Just select the “Tags” group, run the script, then move the subgroups of Inbox > Tags Copy to the “Tags” group of the destination database.

1 Like

That is brilliant, Christian. Thank you!

Hi. I am trying to duplicate an extensive list of tags from one database to another. I have amended the application id in the script above to accommodate DTPro3. - amended script is

tell application id "DNtp"
	try
		set theNum to my duplicateGroups(the selection, incoming group of current database, " copy")
		if theNum is 0 then error "Please select one or more groups."
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

on duplicateGroups(theRecords, theDestination, theSuffix)
	local theRecord, theName, theCopy, theNum
	set theNum to 0
	tell application id "DNtp"
		repeat with theRecord in theRecords
			if type of theRecord is group then
				set theName to ((name of theRecord) as string) & theSuffix
				set theCopy to create record with {name:theName, type:group} in theDestination
				set theNum to theNum + (my duplicateGroups(children of theRecord, theCopy, "")) + 1
			end if
		end repeat
	end tell
	return theNum
end duplicateGroups

I then selected the Tag group of the database I want to copy in the Globals area of the side bar, run the script and get the DT dialogue box “Please select one or more groups”. Think I have already done that, and selecting the tag group again , clicking OK in the dialogue box , appears to terminate the script.i.e. nothing happens. I am new to scripts and DT, perhaps I am missing something. Any help would be appreciated. Thanks

It should work after selecting the tags in the main view, not in the sidebar.

Awesome thanks.

I would like to copy a pretty large tag structure. In DTPro3, this script still works great for copying folder structures.
However, when I try to use it to copy tags, I get an error: “Please select one or more groups” even whenI have selected tags.

Is there a way to update it to copy tags in DT3?

thanks
jason

Did you select the tags in the main view? A sidebar selection is not supported

OK, that was it. I was selecting in the side bar.
It worked when selected in the main window.
Thanks for the help.
jason

When i do this, it actually copies the documents. What am i doing wrong?

The above script should only create groups. A screenshot showing the selection before running the script and a screenshot of the result would be useful. Thanks!

i fixed it! thank you so much!