The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Help Changing an Applescript Thread Tools Search this Thread Display Modes
I was wondering if I could get some help changing the attached applescript. I have switched from Things to Omnifocus and had a great script to turn an email message from Mail.app into a Task.

The script set the subject as the task name, it added the body into the notes section, and also gave me a link back to the message. It also gave the to-do a tag as well. I suck at this sort of thing. Any help would be greatly appreciated as I'm sure others could benefit from this setup as well.

Thank you.
Attached Files
File Type: applescript emailtodo.applescript (12.3 KB, 227 views)
 
Here's an example of how to create a new action in OmniFocus. Hopefully you can keep the Mail parts of your script and then just swap in something like this script:

Code:
tell application "OmniFocus"
	set theDoc to default document
	set theTask to "Buy Cat Food"
	set theNote to "Salmon, not chicken"
	tell front document
		set theContext to context named "Grocery Store"
		set theProject to project named "Cat Maintenance"
		tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext}
	end tell
end tell
 
Lizard's code will certainly work with top-level contexts and top-level projects, but it's possible that you may have some nested contexts, and sooner or later some of your projects may be contained by folders. The code above will fail with these.

One alternative would be to use the parse tasks function, using strings of the pattern described in the OF Help file under: Processing Mail messages into actions

The simplest pattern might use something like this:
Code:
on ParseTask(strText)
	tell application id "OFOC"
		tell default document
			return (parse tasks with transport text strText with as single task)
		end tell
	end tell
end ParseTask
 
Otherwise you can retrieve a nested context with code like this:

Code:
on GetContext(strName)
	if strName ≠ "" then
		tell application "OmniFocus"
			tell default document
				set lstMatches to flattened contexts where name = strName
				if length of lstMatches > 0 then
					return first item of lstMatches
				else
					return (make new context with properties {name:strName})
				end if
			end tell
		end tell
	else
		return missing value
	end if
end GetContext
And you could write a parallel GetProject() by referring to flattened projects and resorting (where necessary) to make new project
 
Looking at your code, you may be able to use something like the code attached below.
(Remember though, that OmniFocus uses one "Context" per task, and does not currently support other tags).

--
Attached Files
File Type: zip MailSeln2OF.applescript.zip (3.2 KB, 198 views)

Last edited by RobTrew; 2012-08-01 at 04:41 AM.. Reason: Placed code in zip file (forum code-display software confused by escape sequences)
 
Thank you guys for your help with this. I think it's 90% there with Rob's last reply. It works, but doesn't link back to the message properly. Attached is a screenshot.

EDIT: Nevermind. Ver 2 of the script links back great. Thank you so much!
Attached Thumbnails
Click image for larger version

Name:	Inbox.png
Views:	250
Size:	57.3 KB
ID:	2480  
 
It was one of those rare scripts which can't be displayed for copying and pasting - the bug arose because the forum software was displaying the code with something missing (getting confused about what was html and what was applescript :-)
 
Before Mountain Lion I was using a different script that I modified to add email to a "Waiting For" project with a set deferred start date. I would use different shortcut keys to activate different versions of the script that would defer the start date by 2days, 1 week, or 2 weeks and add it to my "Waiting For" project.

It stopped working after Mountain Lion.

Is there any way to add a deferred start date to this script?

I assume I need to add something in the following section of code but I'm not sure how to do it:
Code:
			repeat with oMsg in lstSubjectBody
				
				set {strSubject, strBody} to oMsg
				parse tasks with transport text strSubject & strContext & " //" & strBody
Also, adding a default project would be great but I'm guessing it is more complex and I tried writing a parallel GetProject() with no luck.

I really appreciate any help you can provide.

Thanks
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Holidays keep changing TexPine OmniPlan General 0 2011-01-06 03:18 AM
how to applescript changing a row's background color? wfiveash OmniOutliner 3 for Mac 4 2010-10-28 02:02 PM
Changing Inspector Locations w/ Applescript: OmniGraffle cwingrav AppleScripting Omni Apps 1 2010-05-06 12:10 PM
Need basic applescript for changing context tah OmniFocus Extras 8 2009-07-30 12:51 PM
Changing fill color in AppleScript action mduser63 OmniGraffle General 1 2006-06-27 09:23 PM


All times are GMT -8. The time now is 03:09 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.