Tags from content?

Hi,
I’ve a lot of entries that have their tags in the content of the entry in this way:

Some text
TAGS: T1,T2, T3

I’d like to automatically and (possibly) batch convert this ‘tags’ to real new tags but unfortunately I’m a dumb scripter, somebody can help?

Thanks
Nestor

You might have a look at the script ~/Library/Application Support/DEVONthink Pro 2/Scripts/Comments/Convert Comments to Tags.scpt.

Actually I had already made a try but something doesn’t work

tell application id "com.devon-technologies.thinkpro2"
	try
		set thisSelection to the selection
		set allTags to selected text of window 1
		if allTags is not "" then
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
			
			set theTags to text items of allTags
			set AppleScript's text item delimiters to od
			set theTags to (parents of thisSelection) & theTags
			set the tags of thisSelection to theTags
		end if
	end try
end tell

By the way, could it be possible to do it in a batch?
(I mean:
select some entries (that have the same text string before the tags (“tags:”)
getting the tags of each entry
apply the tags)
:wink:

thisSelection is an array, you have to use a loop for each record in the array:


tell application id "com.devon-technologies.thinkpro2"
	try
		set thisSelection to the selection
		set allTags to selected text of window 1
		if allTags is not "" then
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
			
			set theTags to text items of allTags
			set AppleScript's text item delimiters to od
			repeat with theRecord in thisSelection
				set tags of theRecord to (parents of theRecord) & theTags
			end repeat
		end if
	end try
end tell

Sorry I’m really a dumb-scripter and don’t understand what’s an array or loop :cry:

What I meant to do with:


set thisSelection to the selection

was to get the current selected entry for later tagging it.

I rewrote the (wannabe)script and commented it:

tell application id "com.devon-technologies.thinkpro2"
	try
		--get the current selected entry
		set thisSelection to the selection
		--get the current selected text
		set allTags to selected text of window 1
		--split the text into tags
		if allTags is not "" then
			set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
			
			set theTags to text items of allTags
			set AppleScript's text item delimiters to od
			--save the tags in the current selected entry
			set theTags to (parents of thisSelection) & theTags
			set the tags of thisSelection to theTags
		end if
	end try
end tell