RTFD files loose Spotlight comments when imported

Hello!

I want to migrate a bigger database from Together to DEVONthink.

Most of the files are tagged in Together, and Together keeps the tags in the Spotlight comment of these files.

When I drag files from Together into the DEVONthink database the info box shows these tags and the apple script converts them into tags.

Sounds perfect? Well, this does work so far for all file types but one: .trnotes, Together’s own note format.

But these files happen to be just .rtfd files. If I rename their extensions in the finder all programs that are capable of displaying .rtfd files display them properly and the info in the Finder shows their Spotlight comments as well.

But if I move them into DEVONthink the Spotlight comments are gone. So DEVONthink does have no problem with the unknown .trnote file type but with .rtfd which is a very common format.

What can I do? Or what can you do to make DEVONthinkkeep the Spotlight comments when importing .rtfd files?

Sorry for bumping my own thread but I’m desperately trying to find a solution for migrating my database without loosing the tags.

It just came to my mind that there might be a third-party solution for the RTFD comments problem.

These are the facts so far:

  • Together puts its tags into the Spotlight comments of the tagged file.
  • The Together note format .TRNOTE is—as far as I can tell—just a renamed .RTFD.
  • .RTFD is a container format: A folder with the name given to the .RTFD file and in case of Together notes optional tags in the Spotlight comment. Inside of the folder is a file named TXT.rtf and optional other files like images.
  • If the .RTFD container does not contain of any other files than the rich text file it could be a simple .RTF file as well.
  • Possible Solution: A script that batch drags TXT.rtfs out of .RTFD files, renames them after the container folder and adds its Spotlight comments to them.
  • Could be an application as well. Programs that work with the Apple TextEngine can handle both .RTF and .RTFD files—such as TextEdit or Scrivener which automatically replaces imported .RTFD files by .RTF files when they do not contain of more than rich text. But sadly Spotlight comments are lost in the process.

Any suggestions are very appreciated.

A few hours later … and I have found a solution! I have managed to import .RTFD files without loosing the comments! I have just finished a big test run with about 1000 files and everything went great.

I’m writing this not to brag but for the possible benefit of others, and not only Together users.

The workflow is far from perfect and includes pay-for third-party applications but I am sure the whole procedure is totally scriptable—only have I near to no knowledge of AppleScript so I worked with a script only for the final step because I did not find any other way to do this.

So this is what I did:

  • I used the folder action application Hazel because Hazel can read file comments and write them to the file names. I created a simple folder action that changed every file names of files that have comments to

.

As a delimiter I took ###. Whatever you go for, choose something that will under no circumstances be part of a file name. And don’t go for weird characters. I used the Apple apple  first but no script (or search) could ever find it.

Together uses a leading character for tags, the default is &. This allows tags with spaces, for names for example. So a typical file renamed file name would look like this:

Se offendendo###&Hamlet &William Shakespeare &Infinite Jest &David Foster Wallace.trnote

  • Then I batch renamed all the .TRNOTE files to .RTFD with A Better Finder Rename (I’m sure there is a free software to do that).

  • I dragged the renamed files into DEVONthink.

  • I wrote an AppleScript to create tags from the part of the file name following ###. Like I said, I have very little knowledge of AppleScript, but I do have basic programming skills, and with a little help by Apple’s online AppleScript manual I managed to merge code from two of Christian Grunenbergs scripts that come with DEVONthink. And here it is:

-- Convert tags in file names to DEVONthink tags
-- Created by suavito on Tue Jan 4 2011.
-- Based on various AppleScripts by Christian Grunenberg.
-- Copyright (c) 2011. All rights reserved.

tell application id "com.devon-technologies.thinkpro2"
	try
		set these_items to the selection
		if these_items is {} then error "Please select some contents."
		
		repeat with this_item in these_items
			set current_name to the name of this_item
			if current_name contains "###" then
				
				set AppleScript's text item delimiters to {"###"}
				
				set tags_in_name to last text item of current_name
				set cleaned_name to first text item of current_name
				
				set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "&"}
				set theTags to text items of tags_in_name
				set AppleScript's text item delimiters to od
				set theTags to (parents of this_item) & theTags
				set the tags of this_item to theTags
				
				set name of this_item to cleaned_name
				
			end if
		end repeat
	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

Don’t be to harsh on me, I am quite happy with it because I somehow made it work. (And Christian, if you think the creative part was not on my side at all I will change the comment of the script at once.)

If you want to use it just keep in mind that you have to alter the two delimiters to your needs: The first one, ###, tells the script where the real file names ends and the tags strings begins, and the second one, &, where a single tag begins.

  • Phew.

And the last bit for today, but the first you have to use—a script to get the comments into the file names. Run it on .RTFD files in the Finder, then import them into DEVONthink, then run the above script.

Delimiter is again ###. You may change it but you will have to use the same in both scripts.

The script works significantly slower than the aforementioned Hazel folder action, so be patient if you apply it on a huge number of files.

-- Comments to file names
-- Created by suavito on Tue Jan 4 2011.
-- Based on various AppleScripts by Christian Grunenberg.
-- Copyright (c) 2011. All rights reserved.

tell application "Finder"
	try
		set these_items to the selection
		if these_items is {} then error "Please select some contents."
		
		repeat with this_item in these_items
			set this_comment to the comment of this_item
			if this_comment is not "" then
				set current_full_name to name of this_item
				if current_full_name does not contain "###" then
					set AppleScript's text item delimiters to {"."}
					set extension to last text item of current_full_name
					set current_name to first text item of current_full_name
					set new_name to current_name & "###" & this_comment & "." & extension
					set name of this_item to new_name
				end if
			end if
		end repeat
	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


EDIT: The error message at the end is made for DEVONthink and not the Finder. This has to be changed. Just remember: These are my first AppleScripts!

I have to say that is one of the most creative tours-de-force I’ve seen here in a long time. 8)

Congratulations, and welcome to DT!

Thanks, but actually it is procrastination galore. I should have been writing a text which is due on Thursday …