Mail to Quick Entry AppleScript

Here’s a script that:

  • Takes the current Mail.app message
  • Opens the quick entry box
    • Task name is the Subject of the message
    • Task note is the message:// URL of the email
  • Archives the message

Make it an Automator service, give it a keyboard shortcut, and get to Inbox Zero faster than ever!

-- Archive behaviour found at: http://vemedio.com/blog/posts/my-archive-email-apple-script
tell application "Mail"
set theSelectedMessages to selection
set the selected_message to item 1 ¬
	of the theSelectedMessages
set message_id to the message id of the selected_message
set my_subject to the subject of the selected_message

set message_url to "message://%3c" & message_id & "%3e"

set _mb to mailbox of selected_message
set _acct to account of _mb
set _archive_box to _acct's mailbox "Archive"

tell application "OmniFocus"
	tell quick entry
		make new inbox task with properties {name:my_subject, note:message_url}
		open
	end tell
	-- tab into subject pane
	tell application "System Events"
		keystroke tab
	end tell
end tell

move selected_message to _archive_box
end tell

Also as a GitHub Gist (has better formatting)

6 Likes

This is brilliant, thanks!

1st thing I missed testing OF2 and this was such a quick fix.

Now how to get my modified asianefficiency theme back…

I am completely useless for Automator it seems, cannot get your most interesting script to work. Could you please give me a description of how to save your script? I use launchbar to access scripts and services normally.

Sorry: you need to wrap it in on run {input, parameters}...end run to make it work in Automator.

Here’s a good tutorial on AppleScript and Automator.

1 Like

Can you add the mail message body to the notes field in quick entry as well? Can anyone help with how to do that?

set my_body to the content of the selected_message

is what you want. That’s the rich text object.

1 Like

Thanks a lot for that, I ended up saving it in the script editor for now, though. I was on the verge of giving up OF2-testing for now, lacking that functionality.

Best regards,

Arild

Brad - thanks for that!

I’ve had a play with my script, and would ideally like to have the url (to quickly get back to the message) and the text of the e-mail (my_body) in the note. I can change it so I get one or the other, but not both.

Is that possible? I’ve also removed the archive routine, as I like to file the mail

Update - got it! Just needed to use & !!!

Thanks for the script. Is it possible to adjust it so that multiple messages and/or conversations can be selected in Mail and then links to all messages included in the Notes field?

Nick

Probably. theSelectedMessages is a list of all the messages selected, so I guess you’d need to loop over that building up the notes string as you go.

Is this function intended to return to OF2?
Reading some of the replies, and according to my own needs, I think this function is needed.

No. It’s intended to process Mail.app emails.

After the line move selected_message to _archive_box you could get it to focus OmniFocus 2 if that’s your preference.

Bradwright

I feel a bit foolish, but I don’t know how to implement this!

Like others mentioned, this functionality is key key for me to really utilize OF2.
Also, I would like the mail message to not be archived.

Any help would sure be appreciated.

Pete

activate application "com.omnigroup.OmniFocus2" should switch to OmniFocus 2.

adrianwi,
Could you share your final script?
Pete

Here’s my final script from Automator. The link back to the original e-mail doesn’t always work, if you’ve moved it from the original location, but I didn’t want everything dumping in an Archive folder.

[quote]
on run {input, parameters}

-- Send currently selected Mail.app message to OmniFocus 2 quick entry box, then archive it
-- Archive behaviour found at: http://vemedio.com/blog/posts/my-archive-email-apple-script
tell application "Mail"
	set theSelectedMessages to selection
	set the selected_message to item 1 ¬
		of the theSelectedMessages
	set my_body to the content of the selected_message
	set message_id to the message id of the selected_message
	set my_subject to the subject of the selected_message
	
	set message_url to "message://%3c" & message_id & "%3e"
	
	set _mb to mailbox of selected_message
	set _acct to account of _mb
	
	tell application "OmniFocus"
		tell quick entry
			make new inbox task with properties {name:my_subject, note:message_url & my_body}
			open
		end tell
		-- tab into subject pane
		tell application "System Events"
			keystroke tab
		end tell
	end tell
	
	
end tell

return input

end run[/quote]

When i run the script for a selected Exchange mail message using Mail.app, the linkback to the message does not work.

Comparing the message id from this script and another script that gets the last message sent, i can see that the url’s are different. Any idea how to make this work with this script?

Link using your script: message://%3cCF8926EB.B131%mjo@nema.fo%3E
Link using different script where link back works: message://%3C8D63352D-9A4C-4C08-998E-0B247D14910A%40nema.fo%3E

I’m afraid not - my script is based on a standard IMAP server - I assume Exchange uses something different for the Message-Id header.

so I’m 99% sure this is a dumb question, but that’s never stopped me before so why stop now?

Why use this script when you could just clip the email. Only thing I see this script do that clipping doesn’t is move it to an archive folder. But that’s ok as I use Mail Act On to move it to an @Action folder instead.

Just not seeing what this script does that I can’t already do with built in clipping functionality.

It archives the email and lets you move on with processing the next email without leaving your mail client, which is something clipping doesn’t do. Additionally, not everyone uses or wants to use Mail Act On.

It’s worth noting that if you don’t want to use it no-one is forcing you - I’m glad you have a working process with Mail ActOn!