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 Today's Posts

 
AppleScript that adds Waiting For emails from Mail.app (delegated tasks) to OmniFocus Thread Tools Search this Thread Display Modes
whpalmer...I updated my scripts. No success. Dang.
 
I have been playing around with the script and MailTags outbox rules and it seems to be working fine when i send an e-mail from my iCloud account, the task gets added to my Inbox with the Waiting for context.

There seems to be a problem when i send from my Exchange accoutnt - my primary e-mail account. The task does not arrive in OF inbox or does the Growl notification show.

Does anyone have a solution for the Exchange problem?
 
That's interesting @bugvi. I didn't have an iCloud email account, so set one up just to test. I still get no Growl notification or task in my OF inbox when sending from my iCloud address in Mail. I wonder what the difference is in our setup.
 
Thanks for your reply bpwhistler.

This is my Outbox rule set up

If [Any] of the following conditions are met:

[MailTags Keyword] [Is Equal to] [@Waiting]

Run the AppleScript

I use this script:


(*
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 from the App Store 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 : "Waiting for ..."

-- Default start time
property timeStart : "06:00:00"

-- Default due time
property timeDue : "16:00:00"

-- Default start to due date interval, in days
property dateInterval : "3"

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

--Configuration for Growl messages
property GrowlRun : true
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 "Growl")) > 0

--Setup Growl
if GrowlRun then tell application "Growl" 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
set theStartDate to ""
set theDueDate to ""


try
using terms from application "MailTagsScriptingSupport"
set theStartDate to (due date of theMessage) as date
set theStartDate to my setStartDate(theStartDate)
set theDueDate to theStartDate + dateInterval * days
set theDueDate to my setDueDate(theDueDate)
-- set myProject to project of theMessage
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 theTaskTitle 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
if theStartDate is not "" then
set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext, start date:theStartDate}
else
set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext}

end if
if myProject is not null 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 "Growl" 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 setStartDate(theStartDate)
set theDate to (date string of theStartDate)
set newDate to the (date (theDate & " " & timeStart))
return newDate
end setStartDate

on setDueDate(theDueDate)
set theDate to (date string of theDueDate)
set newDate to the (date (theDate & " " & timeDue))
return newDate
end setDueDate
 
Thanks @bugvi. I compared your script to one of mine (I use 3: start date only, due date only, start/due date combined). When I saw that my "start/due date combined" was exactly the same as yours as well as my Mail rule, I realized something else must be going on, since you're able to at least get it to work with your iCloud account. I keep my scripts folder in Dropbox to keep it synced between all my Macs. I use symlinks to redirect. Apparently during the installation of the App store version, my symlinks were corrupted. I rebuilt them and all is good. My scripts now function in both iCloud and my Exchange accounts. This combined with changing my scripts and my launch services database corrected everything.

Thanks bugvi, Lizard, and whparlmer4 for your help.
 
Glad you got it working. As your script is the same as the one i use and i don't use symlinks or the App Store version - i tried to rebuld the Launch Services - but i still can't get it to work with my Exchange account. Tested it again with my iCloud account and it works fine.

Could you possibly send me the scripts that you are using so that i could test using your scripts?

My Exchange account is on Exchange 2007
 
@bugvi...all 3 of my scripts work whether I put a tickle date in or not. If I don't put a tickle date in...it just puts it in the Inbox without any dates. I should also mention that all of these scripts are written using MAS versions of OF and Growl.

This first script is due date only:
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 from the App Store 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 : "Waiting for"

-- Default due time
property timeDue : "11:59:00 PM"

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

--Configuration for Growl messages 
property GrowlRun : true
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 "Growl")) > 0
	
	--Setup Growl
	if GrowlRun then tell application "Growl" 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
			set theDueDate to ""
			
			try
				using terms from application "MailTagsScriptingSupport"
					set theDueDate to (due date of theMessage) as date
					set theDueDate to my setDueDate(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 theTaskTitle 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 id "com.omnigroup.omnifocus.macappstore"
					tell default document
						set theContext to context myWFContext
						
						if theDueDate is not "" then
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext, due date:theDueDate}
						else
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext}
							
						end if
						if myProject is not null 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 "Growl" 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 setDueDate(theDueDate)
	set theDate to (date string of theDueDate)
	set newDate to the (date (theDate & " " & timeDue))
	return newDate
end setDueDate
This script is start date only:
Code:
(*
	Waiting For Mails to OmniFocus Script
	by simplicityisbliss.com, Sven Fechner
	MailTags project and due date compatibility added by Scott Morrison, Indev Software
	This incarnation from Greg Jones

	
	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 from the App Store 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 : "Waiting for"

-- Default start time
property timeStart : "5:00:00 AM"

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

--Configuration for Growl messages 
property GrowlRun : true
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 "Growl")) > 0
	
	--Setup Growl
	if GrowlRun then tell application "Growl" 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
			set theStartDate to ""
			
			try
				using terms from application "MailTagsScriptingSupport"
					set theStartDate to (due date of theMessage) as date
					set theStartDate to my setStartDate(theStartDate)
				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 theTaskTitle 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 id "com.omnigroup.omnifocus.macappstore"
					tell default document
						set theContext to context myWFContext
						
						if theStartDate is not "" then
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext, start date:theStartDate}
						else
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext}
							
						end if
						if myProject is not null 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 "Growl" 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 setStartDate(theStartDate)
	set theDate to (date string of theStartDate)
	set newDate to the (date (theDate & " " & timeStart))
	return newDate
end setStartDate

on setDueDate(theDueDate)
	set theDate to (date string of theDueDate)
	set newDate to the (date (theDate & " " & timeDue))
	return newDate
end setDueDate
This is my script for start and due date:
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 from the App Store 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 : "Waiting for"

-- Default start time
property timeStart : "5:00:00 AM"

-- Default due time
property timeDue : "11:59:00 PM"

-- Default start to due date interval, in days
property dateInterval : "3"

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

--Configuration for Growl messages 
property GrowlRun : true
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 "Growl")) > 0
	
	--Setup Growl
	if GrowlRun then tell application "Growl" 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
			set theStartDate to ""
			set theDueDate to ""
			
			try
				using terms from application "MailTagsScriptingSupport"
					set theStartDate to (due date of theMessage) as date
					set theStartDate to my setStartDate(theStartDate)
					set theDueDate to theStartDate + dateInterval * days
					set theDueDate to my setDueDate(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 theTaskTitle 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 id "com.omnigroup.omnifocus.macappstore"
					tell default document
						set theContext to context myWFContext
						
						if theStartDate is not "" then
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext, start date:theStartDate, due date:theDueDate}
						else
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext}
							
						end if
						if myProject is not null 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 "Growl" 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 setStartDate(theStartDate)
	set theDate to (date string of theStartDate)
	set newDate to the (date (theDate & " " & timeStart))
	return newDate
end setStartDate

on setDueDate(theDueDate)
	set theDate to (date string of theDueDate)
	set newDate to the (date (theDate & " " & timeDue))
	return newDate
end setDueDate
I hope this helps.
 
They only difference is that you are using OmniFocus from the App Store and that i am using application "OmniFocus"

Are you running Exchange 2003, 2007 or 2010

When i send an e-mail from my iCloud account it appears in Sent items instantly while a sent Exchange message takes a few seconds (10-20) until it appears. Might the script get a "message not found" as it is not in the sent items when the script runs?

I tried with another - make outgoing mail red - rule and that works fine on Exchange.
 
I have just started using Omnifocus (previously a Things user) and was very excited when I came across this post for automating waiting for emails. I am using the following code buy can't seem to get it working:

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 from the App Store 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 : "Waiting"

-- Default start time
property timeStart : "5:00:00 AM"

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

-- Default start to due date interval, in days
property dateInterval : "3"

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

--Configuration for Growl messages 
property GrowlRun : true
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 "Growl")) > 0
	
	--Setup Growl
	if GrowlRun then tell application "Growl" 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
			set theStartDate to ""
			set theDueDate to ""
			
			try
				using terms from application "MailTagsScriptingSupport"
					set theStartDate to (due date of theMessage) as date
					set theStartDate to my setStartDate(theStartDate)
					set theDueDate to theStartDate + dateInterval * days
					set theDueDate to my setDueDate(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 theTaskTitle to theRecipientName & (ASCII character 202) & MidFix & (ASCII character 202) & theSubject
				set messageURL to "Created from message://%3C" & (theMessageID) & "%3E"
				display dialog messageURL
				set theBody to messageURL
				if mailBody then set theBody to theBody & return & return & the content of theMessage
				display dialog theBody
				
				-- Add waiting for context task to OmniFocus
				tell application "OmniFocus"
					display dialog "tell omnifocus"
					tell default document
						set theContext to context myWFContext
						display dialog theContext
						
						if theStartDate is not "" then
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext, start date:theStartDate, due date:theDueDate}
						else
							set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, context:theContext}
							
						end if
						if myProject is not null 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 "Growl" 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 setStartDate(theStartDate)
	set theDate to (date string of theStartDate)
	set newDate to the (date (theDate & " " & timeStart))
	return newDate
end setStartDate

on setDueDate(theDueDate)
	set theDate to (date string of theDueDate)
	set newDate to the (date (theDate & " " & timeDue))
	return newDate
end setDueDate
The script is correctly triggered when a "@waiting for" mail is sent and it executes all code up to the "tell application "Omnifocus"". It seems to skip this tell block completely but then does Growl saying that the task has been added.

I know that some people have had problems with MAS store versions but mine is still a trial version. I can use other scripts which use "tell application "Omnifocus"" and they execute without a problem.

Does anyone have any idea what is stopping it from working.

Thanks
 
I bet the try block containing the tell application OmniFocus block is failing, and if you look in your system.log file with the Console application, you may see the reason why. Search for "outboxrule".
 
 




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 07:52 AM
Delegated tasks? mattw OmniFocus 1 for Mac 35 2011-10-07 03:10 PM
Sync with Omnifocus on Mac adds completed tasks.. ohla313 OmniFocus for iPhone 7 2011-06-13 09:50 AM
Script to add delegated tasks from entourage to "Waiting" context in OmniFocus tarun101 OmniFocus Extras 1 2010-05-21 09:09 AM
Adding Tasks Via Send To OmniFocus Mail Rule, Mailtags, & Mail Act-On reuben OmniFocus 1 for Mac 0 2007-11-18 07:07 PM


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


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