Can I change the prefix for printed or saved email

Here is the scenario: we use Google Mail for work. As I haven’t found a way to do an import from Google mail directly, in order to save messages I go into the print dialog and either click “Save” there or actually print to DevonThink (the only difference is that when saving, it puts a footer with the URL on the page).

The annoying bit is, each thus generated PDF has a prefix “Lexmark Mail-” before it - after that comes the subject line of the mail. I save all my files with a date prefix (YYYY-MM-DD) so I have to touch each email I send individually and manually delete the unnecessary bit and add the date.

What I’d love to do is “catch” the file as it comes into the inbox and just replace the “Lexmark Mail” string with the date string. I would presume this isn’t impossible - does anyone have an idea on how that might be done?

Thank you!

Several things left unsaid here. What browser are you using? Are you using Gmail’s Print command (from the More menu) to set up the print preview? Are you using Print > PDF > Save PDF to DEVONthink Pro? Or something else.

Can you access your corporate Gmail account by setting it up in Apple Mail as an IMAP or POP account? This would enable the normal DEVONthink email import – assuming you are using DEVONthink Pro Office, which you didn’t mention.

Could you forward your email to another address whose account is configured in Apple Mail (e.g., use Gmail settings to set up a forwarding filter) – you could create a second personal Gmail account as destination for this and add that account to Apple Mail.

Do you have any idea why “Lexmark --” is added? Where is that coming from? The Safari (assuming you are using Safari) print-to-PDF dialog uses the title of the web page that is being printed for the name of the document, and that is difficult to get around without switching browsers or writing your own print daemon. (Let’s not go there.)

As far as grabbing PDFs on the way to the Inbox – not impossible but not easy. It would be better to write a folder action script (or use Workflow to make a folder action), and use that folder action to do the text & date substitution you want. There are lots of examples in the forum of folder action scripts if you would search for that topic here.

Or, you could use one or more of the scripts in Scripts > Rename – for this I would use the Replace Text… script. This can work on a selection of multiple files simultaneous. You are prompted for the string to find – “Lexmark Mail -” and the replacement text. For that, you could use your preferred date string. This method adds the same date to the selected mail.

There are several other possible scripts in the Rename folder – or use them to customize your own approach.

Hi korm,

unfortunately, the BBS client here doesn’t give me a chance to enter comments in your text, so I’ll try to get this right here.

Browser is Chrome. I use that because it is Gmail and I figure Gmail will work best in Chrome. I’m using the Gmail print command, because if I don’t the email isn’t formatted correctly - i.e. a regular Print from Chrome will do a print of the screen (which I don’t want).
Doing a “Clip to Devonthink” simply reloads Gmail, it doesn’t actually produce something. I can either do the Save PDF->To DevonThink or I can use the “Save” option directly from the Google print dialog. The only difference is that the latter preserves the URL in the footer.

I’ve so far failed accessing the Gmail account from Apple Mail, Airmail and Thunderbird (haven’t tried anything else). Airmail comes closest (it actually sets up the account) but doesn’t import any mail…

Forwarding to another account is possible, though that doesn’t help me much. For one thing, each email would have the “Forward…” line, for another, I wouldn’t be able to answer them using my corp. email address.

The “Lexmark Mail” is likely added as this is the title of the app. If I print to DevonThink from Word, each PDF is prefixed with “Microsoft Word” (which is annoying enough). It seems to be a general thing. Okay, perhaps there is a hidden setting somewhere that will turn this off generally - if there is, I’m more than happy to hear about it :slight_smile:
Mind, the full filename is “Lexmark Mail - xxxx” where xxxx = the subject line of the email. This is why I have to replace just the “Lexmark Mail” with my preferred date format.

A folder action script on the Inbox might be a good chance to solve this, thanks for the idea! I’ll have to check into that.

No, you don’t want to put a folder action on the Inbox. (The Inbox is actually a database not a folder.) What I meant was creating a folder action that changes the title and imports. Add that to your own folder. You can add that folder to Finder’s Favorites in the sidebar for ease of use.

DEVONthink > Install Add-Ons… has an option to install some folder actions that ship with DEVONthink. The are located in ~/Library/Scripts/Folder Action Scripts – any one of those can be used as a starting point. Here’s one that I wrote (based on an earlier script from Criss) that prompts for the tags and name of the imported file record – you could change that part of the logic if you want.

on adding folder items to this_folder after receiving added_items
		if (count of added_items) is greater than 0 then
			tell application id "DNtp"
			end tell
			repeat with theItem in added_items
					set thePath to theItem as text
					if thePath does not end with ".download:" and thePath does not end with ".crdownload:" then
						tell application id "DNtp"
							if thePath ends with ".pdf" then
								set theRecord to ocr file thePath to display group selector
								set theRecord to import thePath to display group selector
							end if
							-- we change the record's name
							set theName to the name of theRecord
							set theNewName to display name editor default answer theName
							set the name of theRecord to theNewName
							-- we add tags to the record
							set theTag to display name editor "Add Tags" info "Tags (separated by semicolons):"
							set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ";"}
							set theTags to text items of theTag
							repeat with theRecord in theSelection
								set tags of theRecord to (parents of theRecord) & theTags
							end repeat
							set AppleScript's text item delimiters to od
							-- we eliminate the old file in the file system
							if exists theRecord then
								tell application "Finder" to delete theItem
							end if
						end tell
					end if
				end try
			end repeat
		end if
	end try
end adding folder items to

If you want to extract the ‘sent date’ from the pdf to incorporate in the name you are going to have to extract that date from the pdf either using a regex or some other method. The script here might help get you started. It extracts the ‘to’ and ‘from’ recipients’ from a pdf but could easily be modified to extract the date.

The easier way would be to get Apple Mail to access your gmail account and then use the Devonthink Mail extension to do the import.


Absolutely correct.
This is a standard option in Apple Mail’s Preferences…

The OP implied this was an enterprise Gmail account (“we use Google Mail for work”), and that they haven’t been able to configure it in Apple Mail or other clients yet (“I’ve so far failed accessing the Gmail account from Apple Mail, Airmail and Thunderbird (haven’t tried anything else). Airmail comes closest (it actually sets up the account) but doesn’t import any mail…”).

Which suggests getting dispensation and advice from the administrator of that account. I use cloud-based Outlook at an agency where I work, but there’s no way the gov would ever let me set that up for POP or IMAP access in a personal mail client.