Specific comment words to tags

I have much spotlight comments in DT that I want to tags.

I have whole sentences in the comments and have thinked about this problem and have a crazy idea about this.

I wonder if it’s possible to do a script that could first analyze the files you have selected (have some temp space somewhere in the process) and go through all your comments.

After this the script takes only comment words who are duped (exist more than one time in total) in the selected files and then create tags only from this dupe comment words. But the cool thing here would be if it’s possible to create some exception list that you can write your own words in the script too and these words will not be tags even if it’s found from some of the dupe comment words of your selected files.

So for an example. If you have comments like:

I like to go out and fishing with my boat
A boat is great to have when you are out and fishing
A bicycle could be hard to use when you are out and fishing

ok, so here are three short sentences about fishing.
I also have some exception list that I don’t want to be to tags:
A, is, are, to, out, when, and, like, go, you

so after the script is finished it will create this tags on the selected files who have this words in the comments:fishing, boat

Is this possible to do a script like this, it would be very cool to have a possibility to choose words you don’t want to be to tags from the comments?

Here’s a simple example, the exceptions might have to be extended of course:


-- Automatic tagging (based on multiple words in the comments)

property exceptions : {"A", "is", "are", "to", "out", "when", "and", "like", "go", "you"}

tell application id "com.devon-technologies.thinkpro2"
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theComment to comment of theRecord
		set theWords to words of theComment
		set theTags to {}
		set processed to {}
		
		repeat with theWord in theWords
			if processed contains theWord and exceptions does not contain theWord and theTags does not contain theWord then set theTags to theTags & theWord
			set processed to processed & theWord
		end repeat
		
		if theTags is not {} then
			set theTags to (tags of theRecord) & theTags
			set tags of theRecord to theTags
		end if
	end repeat
end tell

WOW, thanks for the script Christian, but the sad thing is then I copy the short sentences to spotlight comments to some of the files and run the script, nothing happened… :frowning:

This would be so helpful for me to get this to work :smiley:

Did you use the same sentences? In addition, which version of DEVONthink and Mac OS X are you using?

Yep, I use the same sentences like the example I typed in my question.
I use DT Pro Office 2.5 Build5 and mac os x 10.8.2

I’ve just checked this again and it’s working fine over here (using the same versions), both via Apple’s script editor and via DEVONthink Pro’s scripts menu. Could you please post screenshots of the Info panel before/after executing the script? Thanks!

Here is my attached previews

The strange thing here is that the automatic tagging script doesn’t do the syntax set on the script, it just get the information but don’t set it parameters. Could this help you further in your investigation Christian?

Don’t forget to right click and open the previews in a new tab/window to see the whole screen :wink:



Right now the occurrences are counted per record, therefore it doesn’t work in your case. But it should work if one record has a comment like…

This script should work as desired:


-- Automatic tagging (based on multiple words in all selected comments)

property exceptions : {"A", "is", "are", "to", "out", "when", "and", "like", "go", "you"}

tell application id "com.devon-technologies.thinkpro2"
	set theSelection to the selection
	
	set theTags to {}
	set processed to {}
	
	repeat with theRecord in theSelection
		set theComment to comment of theRecord
		set theWords to words of theComment
		
		repeat with theWord in theWords
			if processed contains theWord and exceptions does not contain theWord and theTags does not contain theWord then set theTags to theTags & theWord
			set processed to processed & theWord
		end repeat
	end repeat
	
	repeat with theRecord in theSelection
		set theComment to comment of theRecord
		set theWords to words of theComment
		set theRecordTags to {}
		
		repeat with theTag in theTags
			if theWords contains theTag then set the theRecordTags to theRecordTags & theTag
		end repeat
		
		if theRecordTags is not {} then
			set theRecordTags to (tags of theRecord) & theRecordTags
			set tags of theRecord to theRecordTags
		end if
	end repeat
end tell

Yes, now it works Christian. Thank you very much for the script and for your help :smiley: :smiley: :smiley:

Cheers