Getting Project Name from Quick Entry

Is there a method to getting the project name from a Quick Entry dialog box? I would like to setup a workflow where email would be automatically filed to a Project folder that is selected in the Quick Entry dialog box. I haven’t seen any way to capture this within a script.

Could you post a screenshot and give an example? If this is possible, maybe I can help.

Here is an example: I use the AppleScript ClipOTron in email to capture follow ups. My workflow would be to:

  1. Invoke the AppleScript ClipOTron
  2. Pick the Project, Context, and Dates
  3. On clicking Save in the Quick Entry, grab the Project name and offer to file the email under a folder of the same name as the project.

Assumes only one email is being captured in the Quick Entry. Here is a view of the Quick Entry Screen

Ok, I think I understand. One question:

A folder in the Finder, Mail or OmniFocus?

I want to file away the original email. The Omnifocus task is going into the right place.

It was a little complex, but I think it would help.
Try this code.

--First draft

property nameMailAccount : "" -- ENTER YOU MAIL ACCOUNT NAME

on run
	tell application "OmniFocus"
		tell quick entry
			set refTask to value of (item 1 of selected trees)
			set nameProject to name of (get assigned container of refTask)
			set refNote to a reference to (note of refTask)
			set mailLink to item 1 of (get value of attribute "link" of style of characters -1 thru -17 of first paragraph of refNote)
		end tell
	end tell
	set theButton to button returned of (display dialog "Do you want to file the email in: " & nameProject & " folder?")
	if theButton = "OK" then
		set refMail to GetMailFromLink(mailLink)
		MoveMail(refMail, nameProject)
	end if
end run

on GetMailFromLink(mailLink)
	set mailID to text ((offset of "%3c" in mailLink) + 3) thru ((offset of "%3e" in mailLink) - 1) of mailLink
	tell application "Mail"
		set lstMails to message 1 of every mailbox of imap account nameMailAccount whose message id = mailID
		set i to 1
		repeat until (item i of lstMails ≠ missing value)
			set i to i + 1
		end repeat
		return item i of lstMails
	end tell
end GetMailFromLink

on MoveMail(refMail, strFolder)
	tell application "Mail"
		set theMailbox to mailbox 1 of imap account nameMailAccount whose name = strFolder
		move refMail to theMailbox
	end tell
end MoveMail
1 Like

unlocked2412: Thx.

So I was able to invoke this script manually in Script Editor after first using the AppleScript version of the ClipOTron script (which you helped me earlier with) I made a small adjustment to how it was searching for the email to be filed. I think I was getting timeouts with the original. I changed this to :

set lstMails to message 1 of message viewer 1 whose message id = mailID

This constrained this to the current message viewer window. Most likely this isn’t going to change as I’m kicking off the script from here.

So now that I got this working, I’m trying to tie this together. Is there a way to kick off this script or set of actions after you hit Save in the Quick Entry. So series of actions go like this:

  1. Select email and run the ClipOTron AppleScript
  2. Fill in the Project/Context/Dates in Quick Entry.
  3. Hit Save button in Quick Entry which then runs this script above.

I don’t think there is a way to throw this logic in but thought I’d ask.

One other item: I’m using an Exchange email account. I think there is a bug in the creation of Mailboxes as sub-folders (i.e. Inbox/Reference Material/Target) I found a couple of threads on this. I was trying to search to see if a folder existed and if not create it. In the example above, AppleScript is creating a folder located here: Inbox/Reference Material/Inbox/Reference Material/Target. (Folder name then turns out to be “Inbox/Reference Material/Target” inside Inbox/Reference Material) It is creating the unnecessary string. Tried this a number of different ways.

You’re welcome, MikeA

I thought about this because, if you don’t have mail running, it would throw an error. But, if you have a lot of mails, searching would be slow.

This script saves the Quick Entry dialog. You can’t program the Save button to trigger a Script. Is that what you mean?

Could you post the script that creates a folder if it doesn’t exist? I could take a look.

To make the folder example simple, this is simply a create sub-folder script. I have the check part working correctly. Basically, this should create a sub-folder Target in the folder Inbox/Reference Material. I included the Event dialog box for when it is run. For some reason it doubles up on the Inbox/Reference Material. Just change below w/Name of your email account that you want to test.

tell application "Mail"
	tell account "Name of Email Account"
		make new mailbox with properties {name:"Inbox/Reference Material/Target"}
	end tell
end tell

I can’t replicate your behaviour because I don’t have an Exchange account. In my case, your script creates the desired hierarchy. But you can try this workaround; the problem is that the new folder takes awhile to appear.

tell application "Mail"
	tell account "Account Name"
		set name of (make new mailbox with properties {name:"Target"}) to "Inbox/Reference Material/Target"
	end tell
end tell

Tell me if you need anything else.

Thx. There definitely seems to be something unusual about how an Exchange account works w/this. This works fine on a different computer w/Gmail. I’ve seen this issue pop up on the Apple forums but didn’t see any resolutions. I’ll keep playing w/this. Thanks again.

I couldn’t test it, but it seems to be the case.
You’re welcome, MikeA.