put skim comments in dt comment box

This might all become irrelevant once dtpro directly support skim, but here’s a rough and ready cript that I use for personal use to tell dtpro to import all of the comments that I have entered in skim into the comment field of the note in dtpro. I at least feel this way that I have a backup of the notes I take, and that devonthink can find them.

it’s rough, but hasn’t caused me any trouble yet. I probably should add a check to find the existing record that has the skim info in it, but i’ve been too lazy to do that. Feel free to modify it as suits your needs…


tell application "DEVONthink Pro"
	if not (exists (think window 1)) then error "No window is open."
	if not (exists selection) then error "please select a record"
	set cur_sel to selection
	if exists (parent 1 of item 1 of cur_sel) then
		set import_location to parent 1 of item 1 of cur_sel
		set import_location to root of database 1
	end if
end tell

repeat with this_record in cur_sel
	tell application "DEVONthink Pro"
		set dt_record_path to path of this_record
	end tell
	set skim_doc to my check_open_skim_documents(dt_record_path)
	tell application "Skim"
		if skim_doc = "" then
			open dt_record_path
			delay 4
			set the_Window to window 1
			set this_document to document of the_Window
			set this_document to skim_doc
		end if
		set accumulated_note to ""
		if exists notes of this_document then
			set the_notes to notes of this_document
			set note_text to ""
			repeat with this_note in the_notes
				set the_page to page of this_note
				log the_page
				set page_string to index of the_page
				if exists text of this_note then set note_text to text of this_note
				if exists extended text of this_note then set note_text to note_text & extended text of this_note
				set accumulated_note to accumulated_note & "
					--------------" & page_string & "-------------------" & " 
				" & note_text
			end repeat
		end if
	end tell
	tell application "DEVONthink Pro"
		set comment of this_record to accumulated_note
---comment out above line to not update dt comments
---commment out below line to not create record in dtpro
		create record with {type:rtf, name:"skim notes from " & (name of this_record), rich text:accumulated_note} in import_location
	end tell
	if skim_doc = "" then tell application "Skim" to close this_document --close it if we opened it
end repeat

on check_open_skim_documents(the_path)
	--checks if skim has record with given path open.  If so, it returns a reference to it. 
	tell application "Skim"
		set doc_properties to get properties of every window
		repeat with this_window in doc_properties
			---figure out where window is 
			---if exists document of this_window then log "this window has document"
			---	if document of this_window does not contain missing value then log "oops"
			if (class of document of this_window) is document then
				set this_document to document of this_window
				if path of this_document is the_path then
					--save this_document
					return this_document
				end if
			end if
		end repeat
	end tell
	return ""
end check_open_skim_documents

erico: As we wait for DT to work nicely with Skim, your script is still most useful. However, notes are imported as plain text, and not RTF. Would you mind giving a hint how to change the script to get RTF notes? (The Skim notes appear to be RTF, as evidenced by examining notes exported directly from Skim.) Thanks!