The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   AppleScript that adds Waiting For emails from Mail.app (delegated tasks) to OmniFocus (http://forums.omnigroup.com/showthread.php?t=12810)

simplicitybliss 2009-06-18 07:27 AM

AppleScript that adds Waiting For emails from Mail.app (delegated tasks) to OmniFocus
 
All,

I've developed a small script that uses MailTags and an Mail.app outbox rule to add a task to the OmniFocus Inbox for every task you delegate by email and tag accordingly before sending. It automatically assigned the right context to the tasks, offers some level of customisation and uses Growl to display notifications once the task has been added to OF.

[URL="http://www.simplicityisbliss.com/2009/06/adding-waiting-for-mail-to-omnifocus-by-applescript/"]Check here for description, instructions and download[/URL]. I hope you enjoy the script and find it as useful as me.

Cheers,

simplicitybliss

menza 2009-06-22 06:09 AM

I cannot get this script working. It simply does not create the task. Any help would be appreciated.

Greg Jones 2009-06-23 01:57 AM

[QUOTE=menza;61523]I cannot get this script working. It simply does not create the task. Any help would be appreciated.[/QUOTE]

Is your waiting context nested by chance? I could not get it to work either if my waiting for context was a sub-context. Once I changed it to a top level context, the script works fine.

As a question to simplicitybliss, I noticed that you include a link to the original email in the OmniFocus task. That link does not work for me-takes me to Mail but the sent message is not selected. It seems logical that the link would not work, as I assume the outgoing message is not written to the 'Sent' items folder until after the outgoing Mail rule is executed, but I'm curious why you included the link, or does the link actually work for you?

simplicitybliss 2009-07-10 05:29 AM

Greg,

I modified the script so that link back to the original email now works. Please check the link to the original blog post to re-download the script from there. Thanks.

With regards to the[B] issue with nested "waiting for contexts"[/B], I haven't have a solution yet, but I can confirm that in this case no task is created and the script stays quiet.

If anyone can help on assigning tasks to a nested context using AppleScript it would be highly appreciated.

Cheers,

simplicitybliss

Greg Jones 2009-07-12 02:03 AM

Link back now works great-thanks!

Eskil 2009-08-05 01:32 AM

I have been able to get this to work and after some googling I have found several places where it is stated that Rules on outgoing will not work automatically since you have apply Rules manually on specifically the folder Sent (I have this stored on our Exchange server if it makes any difference). How do you guys make the Rules work automatically on outgoing mails?

Eskil 2009-08-13 05:23 AM

Hmm.. after a while I figured out that I needed Mail ActOn installed to make Outbox rules, however this didn't quite smoothly anyways. I made an Outbox rule but there seems to be some issue with running the script. All other actions I set on the Outbox rule triggers quite decently (for example setting Mail Tags keywords etc) but the script doesn't run. Any idea on what is wrong?

/Eskil

Greg Jones 2009-08-14 10:50 AM

Sorry I did not see your question sooner on the outbox rules.

As to getting the script to run, make sure that you have a waiting for context that is not nested, and edit the script so that the script matches the name of your context. That's all I needed to do and it worked fine.

Eskil 2009-08-14 01:43 PM

The strange thing is that the rule itself seems to work. If I have the rule as an inbound rule and then manually choose "Apply rules" from the menu the magic happens. But for some reason it doesn't seem like it works when I have the very same rule as an Outbox rule.

I am a bit curious if it has something to do with Exchange 2007. At the moment Mail.app feels very shaky and lots of other problems communicating with the Exchange-server..

Hopefully not many days left of that now..

/Eskil

Greg Jones 2009-08-15 01:07 AM

I'd suggest asking about outbox rules and Exchange 2007 over on the Mail-Act-On [url=http://www.indev.ca/forum/]forum[/url]. That would help narrow the problem down to Exchange or the script.

bpwhistler 2009-08-18 06:56 AM

@simplicitybliss...thanks for a great script. This adds significant efficiency to developing follow-ups to emails.

There's a similar script...but goes the other direction (OF -> Mail)...that I just started using. [URL="http://forums.omnigroup.com/showthread.php?t=12953"]http://forums.omnigroup.com/showthread.php?t=12953[/URL] I made a script suggestion regarding adding the email link-back and Growl support you have in your "Waiting for mails to OmniFocus" script.

Perhaps you would be interested in adding these features to this script? :)

I've been playing around with it...but can't seem to make it work.

invictus26 2009-09-20 09:52 PM

Hey, I'm loving the script. I'm just wondering if it could be modified to open the quick entry box instead of going straight to the inbox. Thanks,

-Matt

lolajl 2009-09-21 11:39 AM

I'm hoping the next version of Thunderbird will have services enabled and scriptable so that I can start using OF with it . . .

kaijin 2009-10-11 11:21 AM

The download and instructions link for the script now reroutes to the blog's main page. It looks like simplictyisbliss.com has undergone an overhaul. I hope simplictybliss will update the link, since I heavily use the script and recommend it often.

[I][COLOR="DarkRed"]-- EDIT[/COLOR][/I]: According to an entry, it looks like simplictybliss is in the process of migrating the blog. [I][COLOR="DarkRed"]--[/COLOR][/I]

Omnipper 2010-04-24 12:56 PM

Any progress in this corner? The link to that AppleScript has not resurfaced.

To recap:
If anyone has any solutions for creating a [I]waiting for[/I] OF [I]inbox[/I] item or [I]quick entry[/I] from an outgoing email in mail.app, I'd love to see it. (Using [I]Mail Act-on , [/I]AppleScript, or whatever.. )

Thanks..

Marc

bpwhistler 2010-04-24 07:51 PM

Here is his script...it's working for me and I just copied it from my scripts folder. I got it from simplicityisbliss awhile ago:

[CODE](*
Waiting For Mails to OmniFocus Script
by simplicityisbliss.com, Sven Fechner

Based on an Outbox Rule in Mail.app this script adds specific messages
to the OmniFocus Inbox with the waiting for context

MailTags (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

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 : "Waiting For"

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

-- Check if there is one or more recipients
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
make new inbox task with properties {name:theTaskTitel, note:theBody, context:theContext}
end tell
end tell
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[/CODE]

Omnipper 2010-04-26 01:17 PM

Thanks Brett,

I ♥ this script. Works great!

--Marc

bpwhistler 2010-04-26 01:27 PM

[QUOTE=Omnipper;76470]Thanks Brett,

I ♥ this script. Works great!

--Marc[/QUOTE]

Not a problem...but the thanks truly goes to simplicityisbliss for writing and sharing such a great script.

kaijin 2010-04-30 05:36 PM

Would it be possible to modify simplicitybliss' wonderful script so that a project (that already exist in OF) and due date assigned via MailTags are grabbed and applied to the waiting for tasks in OF?

smorr@indev.ca 2010-05-05 11:15 AM

Revised AppleScript to make use of MailTags Project and Tickle Dates when composing
 
I have taken the liberty to modify the script created by simplicityIsBliss to add further MailTags compatibility.

This works really well if you set the criteria of the outbox rule to be tickle date is more than 0 days after today. (ie the future), it will run the script when you send a message with a tickle date on and add the task to OmniFocus.

Note -- I have to get Outbox rules working with exchange. I expect this will be soon.


[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 : "Waiting For"

-- !! 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 myProject to project of theMessage
set theDueDate to due date 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 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
[/CODE]

bpwhistler 2010-05-05 01:34 PM

@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.

smorr@indev.ca 2010-05-05 04:00 PM

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.

bpwhistler 2010-05-05 04:56 PM

[QUOTE=smorr@indev.ca;76820]The time should not much to change in the applescript. do you know what time is being set by the script?[/QUOTE]

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.[/QUOTE]

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.

kaijin 2010-05-09 05:16 PM

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.

bpwhistler 2010-06-04 08:49 AM

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.

fudster 2010-06-28 10:17 PM

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

fudster 2010-06-28 10:38 PM

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.

Greg Jones 2010-07-11 08:34 AM

[QUOTE=smorr@indev.ca;76820]The time should not much to change in the applescript. do you know what time is being set by the script?[/QUOTE]

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.

jgrafix 2010-07-25 01:35 PM

Added ability to set due time in script
 
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
[/CODE]

Greg Jones 2010-07-26 01:49 AM

[QUOTE=jgrafix;80778]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.[/QUOTE]

Excellent! This is exactly what I'm looking for-thanks for posting it.

Banesmagic 2010-08-16 10:09 AM

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...

msim 2010-09-30 07:25 PM

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

msim 2010-10-01 08:55 AM

[QUOTE=msim;86529]@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]

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.

whpalmer4 2010-10-01 09:30 AM

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
[/code]

msim 2010-10-01 10:53 AM

@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.

msim 2010-10-03 05:15 PM

@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).

[url=http://skitch.com/smal/d3i4a/mail-image][img]http://img.skitch.com/20101004-ap6ya8kyrmg2r66njjn1ke412.preview.jpg[/img][/url]
[url=http://skitch.com/smal/d3i4a/mail-image]Click for full size[/url] - [color=#A7A7A7]Uploaded with [url=http://skitch.com]Skitch[/url][/color]

fullcity 2010-11-09 03:07 AM

[QUOTE=msim;86728]@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.[/QUOTE]

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

msim 2010-11-09 04:48 AM

[QUOTE=fullcity;88709]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]

Adam, I keep seeing the same issue. As an outbox script it is wonderful, but intermittent success rate makes it unusable :(

whpalmer4 2010-11-09 11:40 AM

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.

invictus26 2010-11-09 07:00 PM

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.

rossonr 2010-12-19 09:12 PM

Copied whpalmer's version and when I got to compile the script I get an error in this section

[CODE] 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[/CODE]

The error is ([B]Syntax Error[/B] Expected “,” but found class name.) and the editor is highlighting date after the word due.

Any help on why it wont compile?

TIA

P.S. Also, does anyone know if there is something like this that will work with Entourage 2008 and omnifocus?

jgrafix 2010-12-27 09:52 AM

@rossonr,

I just grabbed @whpalmer's script and it compiled fine for me. Not sure, but maybe try the copy again.

rossonr 2010-12-28 04:30 AM

Do not know what happened but grabbed it again and I get no errors.

fullcity 2011-03-22 10:44 AM

Is there a way to modify this script so that if the user forgets to set a Tickler Date it will automatically set one? Leaving this value empty causes the script to fail. Methinks it shouldn't (or does anyone beg to differ)?

jpayne 2011-04-05 06:28 AM

Not working reliably
 
For some reason, this isn't working reliably for me with mail.app, Exchange 2007 and snow leopard.

I get growl notifications that the _wrong_ (ie a previously sent untagged) email is added to omnifocus. When I switch to omnifocus i don't see either the correct or the incorrect email in my waiting context.

And then some days it works flawlessly.

papalpha 2011-06-24 08:35 AM

Date handling
 
Hi,

Knowing little of Applescript and such, I made the following variant to get around the issue of the script failing when no date is set (yet keeping the ability to optionally use a set tickler date). Clearly it is hack and not elegant at all, but it seems to work for now..

[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 : " ==>> re: "

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

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

set theDueDate to date "Tuesday, January 1, 1991 12:00:00 AM"
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

-- tell application "GrowlHelperApp" to notify with name notifySuccess title titleSuccess description "test" & txtSuccess application name scriptName
-- do shell script "echo test"


-- 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 theDueDate is not date "Tuesday, January 1, 1991 12:00:00 AM" then
set theTask to make new inbox task with properties {name:theTaskTitel, note:theBody, context:theContext, due date:theDueDate}
else
set theTask to make new inbox task with properties {name:theTaskTitel, 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 "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))
-- tell application "GrowlHelperApp" to notify with name notifySuccess title "test"
return newDate
end setDate[/CODE]

gregia 2011-07-11 06:02 AM

Hi [email]smorr@indev.ca[/email],

[QUOTE=smorr@indev.ca;76810]I have taken the liberty to modify the script created by simplicityIsBliss to add further MailTags compatibility.

This works really well if you set the criteria of the outbox rule to be tickle date is more than 0 days after today. (ie the future), it will run the script when you send a message with a tickle date on and add the task to OmniFocus.
[/QUOTE]

the script works fine - except the problem with assigned nested projects - is there any progress or workaround for this issue?

Thank you for your support!

Gregory

ckennedy 2011-08-10 06:15 AM

Since updating to Lion, this script no longer seems to work. Is it a script issue or a Mailtags issue?

Brian 2011-08-10 02:19 PM

[QUOTE=ckennedy;100432]Since updating to Lion, this script no longer seems to work. Is it a script issue or a Mailtags issue?[/QUOTE]

Are you running the preview build of MailTags 3? Our understanding is that AppleScript support has been temporarily removed from that version of the product.

ckennedy 2011-08-24 10:10 AM

The latest preview of Mailtags has added back applescript and it now functions---partly.
The script now places a task in my OF inbox, but it no longer appends the task with the name of the email recipient-The task name is simply the name of the Subject line for the email.

Brian 2011-08-24 02:08 PM

Hmmm... looks like preview release 1 is still up on their website. I downloaded it from them, but their installer fails on my Mac, and manually installing the plugin into the folder I believe it's meant to live in is causing Mail to crash.

I'll see if one of our test Macs does something else when I install it. The first thing I would check, though, is that the "Mail with MailTags" plug in has been re-enabled in OmniFocus' preferences. One possibility here is that the clipper is using our plain "Mail" plug-in instead of the MailTags one...

Brian 2011-08-24 02:19 PM

Installer worked fine on our test machine, but the version posted on the website is the one without AppleScript support and the "Check for MailTags Updates" under Mail's application menu isn't doing anything on that Mac. (I get neither a "there's an update" or "no update" response - the menu item has no apparent effect.)

Brian 2011-08-24 02:26 PM

Found a direct link to build in a developer's dropbox account in one of the answers on their support pages, but the Preview 2 build I got from the link gives me the same "Script Handler failed" errors that Preview 1 did.

Apologies for the trouble this is causing, but contacting inDev support may be the best move here - if this does turn out to be something we need to modify or change on our end, please let us know and we'll be happy to help...

ckennedy 2011-08-25 04:10 AM

Thanks Brian!

boothy 2011-09-01 11:53 PM

Working Version of Mailtags
 
I've just downloaded a version of Mailtags from the Indev forums here: [URL="http://support.indev.ca/discussions/using-mail-acton/102-mail-act-on-prevents-omnifocus-shortcut-to-work-properly"]http://support.indev.ca/discussions/using-mail-acton/102-mail-act-on-prevents-omnifocus-shortcut-to-work-properly[/URL] - see the bottom of the thread.

It seems to work OK for me, picking up the project, and the due date, but YMMV.

bpwhistler 2012-02-05 01:13 PM

New Growl app not working with script?
 
I recently downloaded the new app store version of Growl. The script still places my "waiting for" action with attached link to email in my Inbox...but I'm not getting a Growl Notification anymore. I have absolutely no idea how to tweak the script to address the new app. Any help would be greatly appreciated.

Thanks...Brett

Not a huge problem...since it still works. I just like to see that Growl notification! :)

Greg Jones 2012-02-07 01:46 AM

[QUOTE=bpwhistler;107052]I recently downloaded the new app store version of Growl. The script still places my "waiting for" action with attached link to email in my Inbox...but I'm not getting a Growl Notification anymore. I have absolutely no idea how to tweak the script to address the new app. Any help would be greatly appreciated.

Thanks...Brett

Not a huge problem...since it still works. I just like to see that Growl notification! :)[/QUOTE]

Haven't tested this much, but I just changed all occurrences of 'GrowlHelperApp' in the script to 'Growl' and it appears to work fine.

bpwhistler 2012-02-07 05:41 AM

[QUOTE=Greg Jones;107119]Haven't tested this much, but I just changed all occurrences of 'GrowlHelperApp' in the script to 'Growl' and it appears to work fine.[/QUOTE]

Thanks Greg. I haven't tested it extensively yet, but it appears to work fine for me too.

Brett

bpwhistler 2012-02-07 02:50 PM

I want to thank Sven Fechner, Scott Morrison, whpalmer4, jgrafix, papalpha, and Greg Jones for the scripts and guidance that has helped me with this. I use this script daily, and find it invaluable. I recently decided to start using more start dates and very few due dates in OF...so utilized the great scripts and advice from you to cobble something together. This script will produce a start date only (no due date) which is determined by entering the tickler date in MailTags. It also works if you don't enter anything in the tickler field...leaving blank start and due fields. I know this isn't that big a deal...but I'm horrible at AppleScript...so this took me awhile to figure out. I figured I'd post it for anybody interested.

[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 : "Waiting for"

-- Default due time
property timeStart : "11:59: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 "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 date "Tuesday, January 1, 1991 11:59:00 PM"
try
using terms from application "MailTagsScriptingSupport"
set theStartDate to (due date of theMessage) as date
set theStartDate to my setDate(theDueDate)
end using terms from
on error theError

end try

-- tell application "Growl" to notify with name notifySuccess title titleSuccess description "test" & txtSuccess application name scriptName
-- do shell script "echo test"


-- 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 theStartDate is not date "Tuesday, January 1, 1991 11:59:00 PM" then
set theTask to make new inbox task with properties {name:theTaskTitel, note:theBody, context:theContext, start date:theStartDate}
else
set theTask to make new inbox task with properties {name:theTaskTitel, 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 setDate(theStartDate)
set theDate to (date string of theStartDate)
set newDate to the (date (theDate & " " & timeStart))
-- tell application "Growl" to notify with name notifySuccess title "test"
return newDate
end setDate[/CODE]

The only thing missing is the ability to dictate my own time...my scripting seems to have killed that functionality and I can't figure out how to get it back. As it is...I keep getting my Start dates at 12:00 AM. If anybody wanted to help me out with this...I'd be very appreciative.

Cheers.

Greg Jones 2012-02-07 05:32 PM

[QUOTE=bpwhistler;107142]The only thing missing is the ability to dictate my own time...my scripting seems to have killed that functionality and I can't figure out how to get it back. As it is...I keep getting my Start dates at 12:00 AM. If anybody wanted to help me out with this...I'd be very appreciative.

Cheers.[/QUOTE]
Here is the modified script that I use. It has start and due dates as well as start and due times. The interval between start and due days is user-defined also. You could pull the set time code out and add it to your script.

[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 («class mtdd» 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 "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, 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
[/code]

bpwhistler 2012-02-07 09:02 PM

Thanks Greg...I ended up using the set time code as you suggested. I also decided to use 3 iterations of the script: 1 for start dates only, 1 for start/due dates (similar to yours), and 1 for due dates only. I'll use @WaitS, @WaitSD, & @WaitD in Mail Tags to trigger them respectively. Thanks for all the help...Brett

bpwhistler 2012-04-10 02:16 PM

I recently upgraded to the App store version of OF. These scripts aren't working anymore! Is this a sandboxing issue?

Thanks,

Brett

bpwhistler 2012-04-13 07:51 PM

Anybody have any ideas about this?

Lizard 2012-04-16 04:46 PM

bpwhistler: It sounds like you may be running into this issue: [url]http://forums.omnigroup.com/showthread.php?t=21496[/url]

In short, you probably need to replace something like this:
[CODE]tell application "OmniFocus"[/CODE]
with something like this:
[CODE]tell application id "com.omnigroup.omnifocus.macappstore"[/CODE]

whpalmer4 2012-04-16 05:40 PM

A different approach might be to rebuild the launch services database, so that it would no longer associate OmniFocus with the downloaded version, but rather the MAS version. I'm assuming here that a tell application "OmniFocus" block will direct the MAS version if the other has never been installed and launched, but don't have any way to verify it, having no MAS apps where I also have the non-MAS version. Seems crazy to have to edit a bunch of scripts!

I know Onyx and TinkerTool both have commands to rebuild the database. It's just a guess that this will fix the problem, but it might be worth trying before breaking out the editor, if you've got a bunch of scripts you'll have to edit.

bpwhistler 2012-04-16 05:51 PM

Thanks Lizard and whpalmer4. I tried to edit one of my scripts as mentioned by Lizard, but found no occurrences of "com.omnigroup.omnifocus." Here is the script I'm using:
[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 "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, 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[/CODE]

Whpalmer4...not really sure how to proceed as you've suggested. I'll check the programs you've mentioned and see if I can stumble my way through it. :)

bpwhistler 2012-04-16 06:07 PM

[QUOTE=whpalmer4;109543]I know Onyx and TinkerTool both have commands to rebuild the database.[/QUOTE]

Is this TinkerTool or TinkerTool System Release 2?

Thanks

bpwhistler 2012-04-16 06:33 PM

whpalmer...I figured out Onyx. Rebuilt my LaunchServices. Script still not functioning.

whpalmer4 2012-04-16 06:39 PM

Hmm. Okay, my understanding of how the system associates apps might be incorrect. Lizard's suggestion should work, I was just hoping you could do it in a cleaner fashion.

Do you still have the old version of OmniFocus installed anywhere on your system?

By the way, you need to replace things like this:

[code]
-- Add waiting for context task to OmniFocus
tell application "OmniFocus"
[/code]

with

[code]
tell application id "com.omnigroup.omnifocus.macappstore"
[/code]

There are some scripts that use

[code]
tell application id "com.omnigroup.omnifocus"
[/code]
instead of
[code]
tell application "OmniFocus"
[/code]

but either way, you need to change the tell application blocks to the form suggested by Lizard.

bpwhistler 2012-04-16 06:53 PM

whpalmer4...I was hoping your way would work too!

No old versions of OF on my machine.

Thanks for the 'simplification' of the script change. I'm not good with AppleScript at all, and my attempts at noodling around with it tend to be unsuccessful without some guidance.

Brett

bpwhistler 2012-04-16 07:23 PM

whpalmer...I updated my scripts. No success. Dang.

bugvi 2012-04-18 12:06 PM

Rule not working on Exchange
 
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?

bpwhistler 2012-04-18 01:03 PM

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.

bugvi 2012-04-19 02:53 AM

Not working with Exchange
 
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 ([url]www.indev.ca[/url]) 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

bpwhistler 2012-04-20 08:18 AM

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.

bugvi 2012-04-21 01:30 PM

Exchange still not working
 
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

bpwhistler 2012-04-21 08:20 PM

@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
[/CODE]

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
[/CODE]

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
[/CODE]

I hope this helps.

bugvi 2012-04-23 03:25 AM

Exchange problems
 
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.

pdoak 2012-04-27 05:12 AM

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[/CODE]

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

whpalmer4 2012-04-27 12:37 PM

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".

pdoak 2012-04-27 12:50 PM

[QUOTE=whpalmer4;109874]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".[/QUOTE]
I looked in the console and I could not find a message containing "outboxrule"
. I don't think that it is the try block that is failing because I placed a "display dialog" just before the tell omnifocus line and that gets displayed when the script runs.

whpalmer4 2012-04-27 01:03 PM

Does the display dialog "tell omnifocus" line get executed?

Puzzling...I don't have the MAS version of Growl, nor do I have Mail Act-on, so I can't really poke around as much as I would like...

If you run this script and don't have OmniFocus running, does it launch OmniFocus correctly?

pdoak 2012-04-27 01:14 PM

If I quit OF and then run the script, OF launches but the email is not in the inbox

whpalmer4 2012-04-27 01:28 PM

What about the display dialog statements inside the tell application "omnifocus" block? Do they produce any output?

pdoak 2012-04-27 01:36 PM

No they don't

whpalmer4 2012-04-27 02:11 PM

And you've looked at the All Items perspective and verified that they didn't end up anywhere in your database, right?

I'd be tempted to comment out the "try" statements, and to perhaps use a different app for doing the display dialog stuff. Once you've commented out the "try" statements, change the myWFContext definition to something that is not in your database, which should cause a runtime error when it hits the "set theContext to context myWFContext" statement. That'll prove that you've set up communication with OmniFocus.

pdoak 2012-04-27 02:35 PM

Okay. I will give it a try tomorrow and let you know the result. Thank you

pdoak 2012-05-01 05:34 AM

I found the problem. The script was falling over at these lines:


[CODE]if myProject is not null then
set theProject to project myProject
move theTask to end of tasks of theProject
end if[/CODE]

Once I removed these lines, it worked. I was not setting a project within mailtags but leaving it blank. Upon closer inspection of the applescript, I can't see where the myProject variable is being set - maybe that was the problem.

jeremyp 2012-05-29 06:46 AM

I have the same lines of code in my script along with


[CODE]using terms from application "MailTagsScriptingSupport"
set theDueDate to (due date of theMessage) as date
set theDueDate to my setDueDate(theDueDate)
set myProject to project of theMessage
end using terms from[/CODE]
The item gets created in the right context but it's never put in the chosen project. Does anyone have any ideas?

whpalmer4 2012-05-29 07:14 AM

You need to actually insert the action in the project, with language like the "move theTask to end of tasks of theProject" that pdoak stripped out. In pdoak's case, the failure was indeed because theProject was not set to a valid value.

jeremyp 2012-05-29 08:09 AM

Thanks for the response. I have the chunk of code that pdoak has stripped out and it still doesn't work (no Projects :-() My entire script is:

[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 : "Mail Follow Up"

-- 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 id "com.Growl.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
set theDueDate to ""


try
using terms from application "MailTagsScriptingSupport"
set theDueDate to (due date of theMessage) as date
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 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
[/CODE]

dangerman 2012-05-29 12:02 PM

Hi,
i have problems to get this script working at all. The first problem is have is to save the script. I get a error message in the "Setup Growl" part that the end of the line is expected ??

Even when i use one of the first version of the script (i can save these versions) i am not able to get mail in my inbox...

Any ideas ?

pdoak 2012-05-29 11:54 PM

[QUOTE=jeremyp;110899]Thanks for the response. I have the chunk of code that pdoak has stripped out and it still doesn't work (no Projects :-() My entire script is:

[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 : "Mail Follow Up"

-- 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 id "com.Growl.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
set theDueDate to ""


try
using terms from application "MailTagsScriptingSupport"
set theDueDate to (due date of theMessage) as date
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 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
[/CODE][/QUOTE]

When trying to get the project from mailbags use:

[CODE]set myproject to project of item 1 of theSelection[/CODE]

See if that solves your problem.

Eike 2012-06-27 01:01 AM

I got exactly the same problem: The scripts adds the task to omnifocus including start date and waiting for-context, but the project will not be included whatsoever.

pdoak's tip to change to
[CODE]set myproject to project of item 1 of theSelection[/CODE]
unfortunately did not work for me.

Update: Ok, now after having read all posts in this thread, I realize it is a known problem with nested projects, i.e. the assignment of a project via MailTags only works at the very first level of OF (projects directly under "library").

As I use folders to distinguish between different areas of responsibility, I would greatly appreciate if anybody find a way to make this script work with nested projects.

bpwhistler 2012-07-28 07:21 AM

Mountain Lion and notification center
 
I've been happily using this script for years. I upgraded to Mountain Lion and have subsequently disabled Growl to see if I like Notification Center. I'm using a program named Hiss to send my Growl notifications to Notification Center currently. Does anybody see a way to bypass the entire Growl/Hiss interface and directly link this script to Notification Center?

Thanks...Brett

mushudog 2012-07-29 01:13 AM

Script not working after ML upgrade
 
Hello,
I have been using this script for a long time, but after ML upgrade is not working any more- task is not added to inbox in OF.

I copied the script in the new com.apple.mail folder but no luck.

Can somebody help or tell me if it is working for you i ML?
====

Update:
I spent all day trying to get this working.
I ended up with a clean reinstall of Mountain Lion - but still no luck. The script is not working at all- no task gets into omnifocus.

I do not know if the script stops because of Mail, Growl, Omnifocus or Mailtags...

Any help is greatly appreciated

larrykkchan 2012-07-31 05:11 PM

same problem here, please help!

tsvoronos 2012-08-08 08:05 AM

Update?
 
Hello, I'm trying out MailTags for the first time and am trying to get the script to work, but if it really doesn't work with Mountain Lion I'm going to save some time! Is this really broken on ML?

SpinalTap 2012-08-13 08:37 AM

[QUOTE=larrykkchan;113166]same problem here, please help![/QUOTE]

Exact same problem here - I cannot even get the script to throw any events to see what is going on.

SpinalTap 2012-08-14 01:53 PM

[QUOTE=SpinalTap;113595]Exact same problem here - I cannot even get the script to throw any events to see what is going on.[/QUOTE]

I did a little more investigation and it appears that the script does not invoke the on_perform_mail_action when executed against a message. Not sure why, but this is the reason it does not execute the bulk of the script. I have tested by removing all the extra stuff and doing some simple display dialog boxes. Still no luck. The "Middle" dialog box never gets executed.

display dialog "Beginning" buttons "OK" default button "OK"

using terms from application "Mail"
on perform mail action with messages this_message for rule this_rule
display dialog "Middle" buttons "OK" default button "OK"
end perform mail action with messages
end using terms from

display dialog "End" buttons "OK" default button "OK"


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

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