The death of an awesome workflow... and seeking help for mail & tags & Devonthink

For most of 2018, I had what felt like an awesome workflow between Apple Mail, and Devonthink. Using a combination of MailTags, Mail Act-On and scripts, I would go through my inbox, delete most of what was there, tag the important messages and fire them off to one of two folders inside Devonthink using hot key commands. It was a fragile workflow, but it felt right and worked for me. Mojave brought a lot of changes to MailTags and over time the most important piece of the machine stopped working, the tags no longer showed up in Devonthink. It was a sad day when those tags stopped showing upā€¦ For a time, I thought I would be fine and just tag in Devonthink. But efficiency is gone and so is my happiness. Mail is piling up. I want my workflow backā€¦

Does anyone have any information about mail and tagging and Devonthink? Is there anyone out there importing mail into Devonthink with tags preserved? I want to keep using Devonthink but wonā€™t be too sad if I have to lose Apple Mail. What about MailMate? Iā€™ve read good things about itā€¦ but can it export to Devonthink with tags? I havenā€™t upgraded to Devonthink 3 yetā€¦ does that new version make any of this easier?

1 Like

Have you asked this in the DT forums? What did they say?

No, I have not posted this in the DT forums, yet. Though I have been checking there. That is the logical place for this kind of question. But it occurred to me this forum might be a good place to toss it out because, well, who knows? It seems like there are a lot of ideas and experimentation here.

I understand, was just curious if you got somewhere on those forums.

question: Do file tags in mojave make it into DT?

Yes, they do make it into DT. Part of the problem with the MailTags plugin is that they seem to have abandoned Mac Finder tags for something proprietary.

I have re-produced Mail Act-On functionality in Keyboard Maestro with Applescripts that saves the mail message and attachments to DEVONthink.

I never found utility in mail tagsā€¦ I find more utility in saving to discrete groups in DT, but with some tweaks to the scripts, someone could add tags to the importing mail items I would thinkā€¦

DT3 does NOT alter this workflow for me.

Rick

3 Likes

can you share the scripts?? :slight_smile:

Thatā€™s great Rick!

For a while I was using something similar but also simplerā€¦ I used Alfred to send mail to one of two locations in Devonthink.

Does Mail ever crash when you execute your scripts?

Mail never crashes with these scriptsā€¦

Iā€™d be happy to upload the KM Macro Group but not sure of a repository to place it inā€¦ basically each KM macro sets the Group name to send the email to in a variable called ā€œMao_Groupā€, then calls the AppleScript. The script is here:

-- Mail Rule - File messages & attachments
-- Created by Christian Grunenberg on Fri May 25 2012.

-- modified by J. Rick Adams, M.D. on January 7, 2017 11:57 for direct saving to a email group
-- May 11, 2019 10:15:49 added omnifocus task creation with DEVONthink URL

-- POSIX path of destination database. Global inbox is used if not specified.
property pDatabasePath : "/YOUR PATH to DATABASE.dtBase2"
tell application "Keyboard Maestro Engine"
	-- grabs the destination "group name" which was set in Keyboard Maestrol
	set pEmailGroup to getvariable "mao_Group"
	set theParameters to getvariable "mao_Parameters"
end tell

-- This string is used when the message subject is empty
property pNoSubjectString : "(no subject)"

tell application "DEVONthink 3"
	set destination_database to open database pDatabasePath -- Ensure that the database is open
	set groupList to (every record whose type is group and name is "Emails") of destination_database
	set emailGroup to first item of groupList
	set groupList to every child of emailGroup whose type is group and name is pEmailGroup
	if (count of groupList) < 1 then
		display alert "Alert" message "Error finding group named " & pEmailGroup & "."
		return
	end if
	
	set message_group to first item of groupList
end tell

tell application "Mail"
	set theMessages to the selection
	set theFolder to (POSIX path of (path to temporary items))
	repeat with theMessage in theMessages
		try
			tell theMessage
				set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
			end tell
			if theSubject is equal to "" then set theSubject to pNoSubjectString
			
			tell application "DEVONthink 3"
				set newRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(theReadFlag)} in message_group
				set unread of newRecord to theReadFlag
				set recordURL to reference URL of newRecord
			end tell
			
			if theParameters contains "OmniFocus" then
				my doOmnifocus(recordURL, theMessage, extract name from sender of theMessage)
			end if
			
			repeat with theAttachment in mail attachments of theMessage
				set theFile to theFolder & (name of theAttachment)
				tell theAttachment to save in theFile
				tell application "DEVONthink 3"
					set theAttachmentRecord to import theFile to message_group
					set unread of theAttachmentRecord to (theReadFlag)
					set URL of theAttachmentRecord to theSender
				end tell
			end repeat
			
			set read status of theMessage to true
			
			display notification "Email '" & theSubject & Ā¬
				"' was sent to " & pEmailGroup
			
			-- move the message to Trash
			set theAccount to account of mailbox of theMessage
			set mailbox of theMessage to mailbox "Trash" of theAccount
			
		on error errMsg
			display dialog "ERROR: " & errMsg
		end try
	end repeat
	-- if window of message viewer 1 = window 1 then -- get selection and process
	
	-- end if
end tell

on doOmnifocus(DTrecordURL, theMessage, theSender)
	using terms from application "Mail"
		set theSubject to subject of theMessage
		set theTask to "follow up with " & theSender & " about " & theSubject
		set theNote to DTrecordURL & return & return & "From: " & theSender & return & "Subject: " & theSubject & return & "Date: " & date received of theMessage & return & "----------" & return & return & content of theMessage
	end using terms from
	
	tell application "OmniFocus"
		activate
		tell quick entry
			open
			activate
			make new inbox task with properties {name:theTask, note:theNote}
		end tell
		tell application "System Events" to keystroke tab
	end tell
end doOmnifocus
1 Like

You could just export the km group and post/upload it here? The kmmacros file will be disabled on import, so nothing really dangerous should happen. (Select the group -> export macros and done)

Thanks for sharing the script. It definitely has me thinking about your version of this workflow.

Sending emails to Devonthink on the fly with nothing more than a keyboard command is golden. In my way of thinking it is desirable because the email app turns into something simpler, like a sorter, and the power and functionality of Devonthink is then available for whatā€™s valuable, the mail that needs to stay, be available for referencing and archived. This was at the heart of my workflow. The trouble is that I also have been using tags.

What I liked about my set up was that all my mail went into one big file folder in Devonthink, one giant bucket, and that was so easy and also because of the tags. I like tags because some categories of things seem easier to connect as opposed to using the search function. For instance, my tag for ā€œ2019-taxesā€ immediately gathers a wide assortment of mail and other documents relevant to the job of filing my tax returns.

I know there is more for me to learn about doing effective, deep searches in Devonthink and creating smart groupsā€¦ Perhaps if I learned to use these more effectively I wouldnā€™t need tags and wouldnā€™t miss them. For now, I still would like to tag mail ā€œon the flyā€ and send them to Devonthink ā€œon the fly.ā€

uploaded files required to be jpg, gif, etc. From what Iā€™m able to figure out, only images are able to be uploaded. Happy for you to show me otherwise.

Rick

would be easy enoughā€¦

change the script to find the emailGroup and stop there. i.e., after

set groupList to (every record whose type is group and name is "Emails") of destination_database
set emailGroup to first item of groupList

donā€™t go on to find/declare the variable ā€˜message_groupā€™. Delete the lines:

set groupList to every child of emailGroup whose type is group and name is pEmailGroup
if (count of groupList) < 1 then
	display alert "Alert" message "Error finding group named " & pEmailGroup & "."
	return
end if
set message_group to first item of groupList

then after youā€™ve created the DT new record you can set the tags you want.

Letā€™s say in KM youā€™ve set the variable ā€œmao_Tagsā€ to ā€œtaxes_2019,taxes,investmentsā€

change

tell application "Keyboard Maestro Engine"
	-- grabs the destination "group name" which was set in Keyboard Maestro
	set pEmailGroup to getvariable "mao_Group"

to

 tell application "Keyboard Maestro Engine"
	-- grabs the tags variable which was set in Keyboard Maestro
	set theTags to getvariable "mao_Tags"

then after you create the DT record with

set newRecord to create record with {name:theSubject & ".eml", type: *unknown* , creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string ), unread:(theReadFlag)} in message_group` 

you can create the tag list:

set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
set tag_list to text items of theTags
set AppleScript's text item delimiters to astid

then add the tags to the DT record:

set tags of newRecord to tag_list

Rick

ah, that could be, did not know that.
Maybe you could post it in the Keyboard Maestro forums and link to it here?
(just a thought :slight_smile: )

Thatā€™s impressive. So Iā€™m wondering to myself if that workflow is reproducible in Alfredā€¦ or perhaps I need to look seriously at getting Keyboard Maestroā€¦

This is almost a year too late, but I thought worth adding: the MailMate -> DevonThink flow is very straightforward (and while weā€™re here, so is the MailMate -> OmniFocus flow, etc, all by installing the appropriate Bundle for MailMate).

2 Likes

Yes! I did discover this several months ago. After all my struggle with Apple Mail, I decided to give Mailmate a try about six months ago. Exporting to Devonthink works easily and seems solid. My one wish is for compatibility of tags. Tags applied to messages in Mailmate are not transferrable. But there have been enough other positives with using Mailmate that I continue to use it even though Iā€™ve had to settle, somewhat, in terms of my ideal mail workflow.

1 Like