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
@smorr@indev.ca...thanks for the update. Works well. I would ask one thing. The ability in MailTags to set a default time for the Tickler. As it is, the Tickler is sent to OF with the time of the email as the time due. I have my default time for all tasks set to 11:59 pm on the due date of the task in OF. I still have to modify time in the tasks sent to OF from script/MailTags.

I have another unrelated question for you regarding this script. Curt Clifton wrote a script that allows you to initiate an email from a task. When you run this script (with the relevant task highlighted), it autocompletes the task and creates a new task with the prefix "waiting for reply" (or whatever you choose to put in the script). It also opens a new email with the subject of the task as the subject of the email. Now the question...is there any way to link simplicityisbliss's script back to the task that was created by Curt Clifton's script? If you need to see Curt's script...let me know. I've been beating this idea to death and haven't come up with a way to do it. I'm also a VERY novice scripter.

As I read this back...I'm amazed that english is my primary language. If you didn't understand let me know and I'll try to clarify.
 
The time should not much to change in the applescript. do you know what time is being set by the script?

As for the other script -- I believe the URL of the message is placed in the notes of the task -- it shouldn't be too difficult to parse this out.
 
Quote:
Originally Posted by smorr@indev.ca View Post
The time should not much to change in the applescript. do you know what time is being set by the script?
If I send the email (with the tickler in MailTags set to 5/8/2010) at 6:22 PM tonight...then the task has a due date of 5/8/2010 at 6:22 PM. The script (time the email is sent) is setting the due date time rather than the default setting in OF.

Quote:
As for the other script -- I believe the URL of the message is placed in the notes of the task -- it shouldn't be too difficult to parse this out.
That's true...simplicityisbliss's (SIB's) script does place the URL in the notes field. My problem is...
1. Curt's script originates the email at the same time as the new task.
2. The new task is in the same project/context/due date/due time
3. The new email has the new appended prefix "waiting for reply"
4. I would like this new email (generated by Curt's script) to somehow be linked back to the newly generated task (preserving the project hierarchy and everything else in the notes field)...and this can't happen until SIB's script runs and creates a URL
5. When I send out the new email with SIB's script (now modified to have a new due date) I want the link to go into the task that was created by Curt's script (preserving notes & project) but with new due date and context (as created by SIB's script w/ MailTags "help")
6. So...how do I get the URL, new due date, and context to modify the newly created task? Or am I trying to make a really simple thing REALLY hard? I do that...

I know this sounds like a bunch of crap...and it probably is. I've got it in my head that it will work and improve my work flow. I don't mind shuffling things around by hand...but I've become addicted to scripts and am hoping to cut out yet another step.
 
Thanks for the modified script, smorr! The project is correctly assigned to the new waiting for task as long as the project is a first-level parent. If a project is nested in a folder (other than Library), the task is added to the Inbox with no project assigned. I believe this is expected behavior and have observed it in other scripts, but am curious if there is a way for nested projects to be retrieved by scripts.
 
I've never had any problems with the original script...but am having difficulties with the modified script with the tickler added. The difficulty I'm experiencing is that the task generated by the script seems to "disappear" in OF frequently. I search for the name (as displayed by Growl), I browse through my different folders. No luck. Growl notifies me that a task has been successfully generated. I can't seem to put a finger on when it does and doesn't happen. When I send an email to myself with the @waiting and tickler set...it arrives in my inbox. Otherwise it appears to be a crapshoot. Kaijin mentioned above that is assigned to the correct 1st level project. How do you specify which project the task belongs to. I'm a rookie at this game and must be missing things.

I'm also still having difficulties with the time generated. When I set the tickler date in MailTags and then send the message, the time set for the due date is the time the message was sent. This doesn't work in my flow. I set all of my due date times at 11:59 pm on the date they are due. Is there a way to specify this in MailTags?

Thanks.
 
I'm trying to get Sven's script working, hoping someone can tell me what I'm missing.

I have installed Mail Act-On, and I'm calling Sven's applescript in an outbox rule.

A new OmniFocus inbox task is indeed created - but the problem is that it's not created from the email I just sent. Instead, it's based on whatever row I have selected in the mail.app window.

I'm trying to determine what I should use instead of:

set theMessages to |SelectedMessages| of theData

... because suspect that this syntax should indeed do exactly what I'm observing. The confusing part for me is - it seems that this code worked for the rest of you...

still looking - meanwhile, any help would be great. Cheers
 
Nevermind my post everyone. For some reason, initially the script was indeed creating inbox tasks based on the selected row in mail.app. I must have configured something wrong in Mail Act-On, I haven't been able to determine what it was.

I did comment out some code from the script that was causing the script to fail (i.e. not complete successfully) - the assignment of the project and the due date. I don't need either.

Again sorry for the noise.
 
Quote:
Originally Posted by smorr@indev.ca View Post
The time should not much to change in the applescript. do you know what time is being set by the script?
Well, I've tried to fix this myself, but I've not had any success. The time being set is the actual time that the script is executed. The MailTags Message.scriptSuite appears to use the NSDate, so the date passed to OmniFocus includes hours, minutes, and seconds. The preferred action would be to pass the month, day, and year only so that the default due time in OmniFocus will be applied.

I've tried to tweak the script to parse the time data from the date, but when I do so the script appears to run successfully (according to Growl) but the task disappears just as @bpwhistler described. Any knowledgeable scripters have any thoughts? It's just so close to being perfect as is, but the time of day problem makes it unworkable for me. I might as well create the task manually if I have to go back to the task and edit the due date to change the time stamp on automated tasks.
 
All,

I'm not sure if this will solve the intermittent disappearing problem, but I've updated the script to include a "Time Due" property that you can set within the script so that the OF date due will have your preferred time due as well. I'm only guessing that passing a date with no time creates some anomalies within OF.

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"

-- !! 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
					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}
						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

Last edited by jgrafix; 2010-07-29 at 09:32 AM..
 
Quote:
Originally Posted by jgrafix View Post
All,

I'm not sure if this will solve the intermittent disappearing problem, but I've updated the script to include a "Time Due" property that you can set within the script so that the OF date due will have your preferred time due as well. I'm only guessing that passing at date with no time creates some anomalies within OF.
Excellent! This is exactly what I'm looking for-thanks for posting it.
 
 


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 06:32 PM.


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