Contribution: script to send Outlook Notes to DEVONthink

I adapted Christian Grunenberg’s script for importing Microsoft Outlook email Messages to do the same for Outlook Notes, Add Note(s) to DEVONthink.

The advantage of scripting over other methods is that the script retrieves the creation and mod dates from Outlook and sets them in the DT version of the note. I rely on these properties for sorting.

Unfortunately, images embedded in Notes are not carried over. That is true for other transfer methods except for print to PDF --> DT Inbox.

Is it acceptable practice to put text of a lengthy script into a forum post?


It certainly is. You can also ZIP and upload it as an attachment to your post.

Here is the script, Add Note(s) to DEVONthink

-- Michael Myers, Apr 11, 2018
-- Imports selected Microsoft Outlook Notes into DTpro, adapted from Christian Grunenberg's script for Outlook Messages
-- Caveats:
--   Images in Outlook Notes are not carried over to DEVONthink. Most rich text formatting is preserved.
--   When update Category property of Outlook Note with a custom tag (e.g. "Sent to DEVONthink"), this touches the modification date of Note in Outlook. 

-- Import selected Microsoft Outlook Notes to DEVONthink Pro.
-- Original Messages script created by Christian Grunenberg on Dec 08 2010.
-- Copyright (c) 2010-2015. All rights reserved.

-- this string is used when the Note name is empty
property pNoSubjectString : "(no name)"

tell application "Microsoft Outlook"
		set theSelection to the selected objects
		if theSelection is {} then error "One or more Notes must be selected."
		tell application id "DNtp"
			if not (exists current database) then error "No database is in use."
			set theGroup to preferred import destination
		end tell
		repeat with theNote in theSelection
				-- useful properties of note object:
				--     category:{}
				--     creation date: date ""
				--     modification date: date ""
				--     name:""
				--     content:""
				--     plain text content:""
				--     exchange id:""
				--     class:note
				if class of theNote is not note then error "One or more Note items must be selected."
				set theName to (name of theNote)
				if theName is equal to "" then set theName to pNoNameString
				set theCreationDate to (creation date of theNote)
				set theModificationDate to (modification date of theNote)
				set theContent to (content of theNote)
				set exchangeID to (exchange id of theNote) -- could this id be used to link back to original item in Outlook?
				set theCategories to {}
				set theList to (category of theNote)
				repeat with theCategory in theList
					set theCategories to theCategories & (name of theCategory)
				end repeat
				-- start code to tag item in Outlook with "Sent to DEVONthink" (tag == a Category item in Outlook parlance)
				-- caution: if implement following code, the modification date of the source note in Outlook is changed to day of script execution
				-- if source note already tagged, don't tag it again
				set devonTagged to false
				repeat with theCategory in theList
					if (name of theCategory) is "Sent to DEVONthink" then
						set devonTagged to true
						exit repeat
					end if
				end repeat
				if devonTagged is false then set end of theList to category "Sent to DEVONthink"
					tell application "Microsoft Outlook" to set category of theNote to theList
					-- cannot restore old mod date, it is a read only property in Outlook
					-- tell application "Microsoft Outlook" to set modification date of theNote to theModificationDate
				on error error_message number error_number
				end try
				-- end of tagging code
				tell application id "DNtp"
					set theRecord to create record with {name:theName & ".html", type:unknown, creation date:theCreationDate, modification date:theModificationDate, URL:"none", source:theContent} in theGroup
					if theCategories is not {} then
						set theTags to tags of theRecord
						set theTags to theTags & theCategories
						set tags of theRecord to theTags
					end if
					set state of theRecord to true -- unlike email Message, Note state is always true
				end tell
			end try
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "Outlook" message error_message as warning
	end try
end tell

do you have also a script to send message do DT? I’ve made a search and the ones I’ve found doesn’t work.
Thanks friends.