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

 
AppleScript that adds Waiting For emails from Mail.app (delegated tasks) to OmniFocus Thread Tools Search this Thread Display Modes
I am having a similar problem. The email selected "from the rule" is the previously sent mail - not the one with the actual "Waiting" tag. For the life of me I have no idea what is happening...
 
@jgrafix: your script appears to achieve exactly what i want to achieve. but i am not able to make it work.

i have mail acton installed. i also have mailtags installed. i created a outbox rule (as mentioned withing the script). oh and i also created a context "Follow up"

and now when i send a mail with tickler date set, no growl message and no action in OF.

can you help!?

thanks!!
 
Quote:
Originally Posted by msim View Post
@jgrafix: your script appears to achieve exactly what i want to achieve. but i am not able to make it work.

i have mail acton installed. i also have mailtags installed. i created a outbox rule (as mentioned withing the script). oh and i also created a context "Follow up"

and now when i send a mail with tickler date set, no growl message and no action in OF.

can you help!?

thanks!!
i tinkered some more with the mail acton rule. changed the rule to trigger if "tickle date" is set, and now the script works.
this is great, and thank you!!

now i am wondering if anybody here has felt the need to set the start date on such new actions to 2 (or x number of)days before the due date.

i went through the apple script and thought i might be able to do it. but given i did coding 15 years ago, i do not think i can do that cleanly.

so if somebody else here has already done this, or does not mind spending the 10 minutes that it would take, i would be very thankful.

cheers.
 
I think the enclosed version should do what you want, but I don't have Mail Act-On so I can't test it directly. Edit the value of "leadStart" to control the number of days of lead time you get, or set it to 0 to disable setting a start date. If you want to specify the lead time in hours, change "leadStart * days" to "leadStart * hours". If you want a fixed start time, that's left as an exercise for the reader :)

Code:
(*
	Waiting For Mails to OmniFocus Script
	by simplicityisbliss.com, Sven Fechner
	MailTags project and due date compatibility added by Scott Morrison, Indev Software
	
	Based on an Outbox Rule (Mail Act-On) in Mail.app this script adds specific messages
	to the OmniFocus Inbox with the waiting for context
	
	MailTags is required to automatically set the project and the due date.

	Mail Act-On (www.indev.ca) is required to define the Outbox Rule to only
	create tasks for those outgoing emails that are to be tracked in OmniFocus
	
	A sample Outbox rule may be
	if MailTags Tickle Date is After 0 days today  
	Run Apple Script: [ThisAppleScript]
	
				
	The script uses Growl for feedback notification if it is installed and running
	
*)


--!! EDIT THE PROPERTIES BELOW TO MEET YOUR NEEDS !!--

-- Do you want the actualy mail body to be added to the notes section of the OmniFocus task?
-- Set to 'true' is or 'false' if no
property mailBody : true

-- Text between mail recipient (the person you are waiting for to come back) and the email subject
property MidFix : "to follow up re:"

-- Name of your Waiting For context in OmniFocus
property myWFContext : "Follow Up"

-- Default due time
property timeDue : "5:00:00 PM"

-- Default lead time for start date, in days, or 0 if start date not desired
property leadStart : 2

-- !! STOP EDITING HERE IF NOT FAMILAR WITH APPLESCRIPT !! --

--Configuration for Growl messages 
property GrowlRun : false
property scriptName : "Waiting For Mails to OmniFocus"
property notifySuccess : "Success Notification"
property notifyFail : "Failed Notification"
property titleSuccess : "Waiting For Mail added"
property titleFail : "Waiting For Mail to OmniFocus FAILED"
property txtSuccess : " added to OmniFocus successfully"
property txtFail : " to OmniFocus to add successfully"
property txtIcon : "OmniFocus"

on perform_mail_action(theData)
	
	--Check if Growl is running
	tell application "System Events" to set GrowlRun to (count of (every process whose name is "GrowlHelperApp")) > 0
	
	--Setup Growl
	if GrowlRun then tell application "GrowlHelperApp" to register as application scriptName all notifications {notifySuccess, notifyFail} default notifications {notifySuccess, notifyFail} icon of application txtIcon
	
	--Get going
	tell application "Mail"
		set theMessages to |SelectedMessages| of theData --Extract the messages from the rule
		repeat with theMessage in theMessages
			set theSubject to subject of theMessage
			set theRecipient to name of to recipient of theMessage
			set theMessageID to urlencode(the message id of theMessage) of me
			try
				using terms from application "MailTagsScriptingSupport"
				set theDueDate to (due date of theMessage) as date
				if (leadStart is not 0) then
					set theStartDate to theDueDate - leadStart * days
				else
					set theStartDate to missing value
				end if
				
				set theDueDate to my setDate(theDueDate)
				end using terms from
			on error theError
				
			end try
			
			-- Check if there is one or more recipients
			try
				if (count of theRecipient) > 1 then
					set theRecipientName to (item 1 of theRecipient & (ASCII character 202) & "and" & (ASCII character 202) & ((count of theRecipient) - 1) as string) & (ASCII character 202) & "more"
				else
					set theRecipientName to item 1 of theRecipient
				end if
				
				set theTaskTitel to theRecipientName & (ASCII character 202) & MidFix & (ASCII character 202) & theSubject
				set messageURL to "Created from message://%3C" & (theMessageID) & "%3E"
				set theBody to messageURL
				if mailBody then set theBody to theBody & return & return & the content of theMessage
				
				-- Add waiting for context task to OmniFocus
				tell application "OmniFocus"
					tell default document
						set theContext to context myWFContext
						set theTask to make new inbox task with properties {name:theTaskTitel, note:theBody, context:theContext, due date:theDueDate, start date:theStartDate}
						if myProject is not "" then
							set theProject to project myProject
							move theTask to end of tasks of theProject
							
						end if
					end tell
				end tell
				
			on error theError
				do shell script "logger -t outboxrule 'Error : " & theError & "' "
			end try
			
			my GrowlSuccess("Mail: " & theSubject)
		end repeat
	end tell
	
end perform_mail_action

on GrowlSuccess(theMessage)
	if GrowlRun then tell application "GrowlHelperApp" to notify with name notifySuccess title titleSuccess description theMessage & txtSuccess application name scriptName
end GrowlSuccess

on urlencode(theText)
	set theTextEnc to ""
	repeat with eachChar in characters of theText
		set useChar to eachChar
		set eachCharNum to ASCII number of eachChar
		if eachCharNum = 32 then
			set useChar to "+"
		else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
			set firstDig to round (eachCharNum / 16) rounding down
			set secondDig to eachCharNum mod 16
			if firstDig > 9 then
				set aNum to firstDig + 55
				set firstDig to ASCII character aNum
			end if
			if secondDig > 9 then
				set aNum to secondDig + 55
				set secondDig to ASCII character aNum
			end if
			set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
			set useChar to numHex
		end if
		set theTextEnc to theTextEnc & useChar as string
	end repeat
	return theTextEnc
end urlencode

on setDate(theDueDate)
	set theDate to (date string of theDueDate)
	set newDate to the (date (theDate & " " & timeDue))
	return newDate
end setDate
 
@whpalmer anf @jgrafix - big huge thanks!!
i copied this one and it works smoothly.

what i have done is that i am using this on outgoing mails with mailtags tickle date set.
and i am using the ctrl-O to run this script using mail acton, instead of running clipotron.

many thanks again!! this totally rocks.
 
@whpalmer: hey i started using this script. then realized that it works intermittently and i am unable to understand the situation under which it does not work. When i add some mails using this script, by calling it using a Mail Acton shortcut, it does not add a task in OF even though Growl indicates success.

Any ideas as to why this mail may work sometimes and not at other times? Or is it that mail is only able to work on outgoing messages?

I did more trial and error, and I am unable to isolate a particular cause for when it does not work :(

I do like what this script does far more than the inbuilt Clipotron. So trying to get this to work...


----

I suspect this is irrelevant but just in case there is a clue here

here is an image from at&t (this is sent by at&t to an email that is not in my address book entry but has been added to Omnifocus in properties under mail tab).


Click for full size - Uploaded with Skitch

Last edited by msim; 2010-10-03 at 05:49 PM..
 
Quote:
Originally Posted by msim View Post
@whpalmer: hey i started using this script. then realized that it works intermittently and i am unable to understand the situation under which it does not work. When i add some mails using this script, by calling it using a Mail Acton shortcut, it does not add a task in OF even though Growl indicates success.
Ditto here. I get the Growl success but nothing shows up in OF. I am calling the script using an Outbox rule that looks for a specific MailTag keyword.

Thx,
Adam
 
Quote:
Originally Posted by fullcity View Post
Ditto here. I get the Growl success but nothing shows up in OF. I am calling the script using an Outbox rule that looks for a specific MailTag keyword.

Thx,
Adam
Adam, I keep seeing the same issue. As an outbox script it is wonderful, but intermittent success rate makes it unusable :(
 
As I mentioned previously, I don't have Mail ActOn, so my ability to investigate is hindered. However, reading the script, it is structured so that it sends Growl a notification of success even if some sort of error is encountered, so it isn't surprising that things are "disappearing" despite Growl reporting that the script ran successfully.

If you're having the problem, fire up the Console application in your Utilities folder, and type "outboxrule" into the search box at upper right after clicking on All Messages under Database Searches on the left. That should show you the error messages that have been emitted by the script, and perhaps give a clue as to what is going on.
 
Does your Acton rule also move the mail message? Apparently moving the message interferes with running Applescripts. I've resorted to having one rule to send the email to OF and another to move it to another folder.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to deal with delegated or "waiting for" actions bisimpson Applying OmniFocus 20 2013-02-27 06:52 AM
Delegated tasks? mattw OmniFocus 1 for Mac 35 2011-10-07 02:10 PM
Sync with Omnifocus on Mac adds completed tasks.. ohla313 OmniFocus for iPhone 7 2011-06-13 08:50 AM
Script to add delegated tasks from entourage to "Waiting" context in OmniFocus tarun101 OmniFocus Extras 1 2010-05-21 08:09 AM
Adding Tasks Via Send To OmniFocus Mail Rule, Mailtags, & Mail Act-On reuben OmniFocus 1 for Mac 0 2007-11-18 06:07 PM


All times are GMT -8. The time now is 03:50 PM.


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