The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Script for getting rid of task notes automatically? (http://forums.omnigroup.com/showthread.php?t=21615)

FMiguélez 2011-07-14 12:00 PM

Script for getting rid of task notes automatically? (Resolved)
 
Hello.

I've setup certain iCal alarms to show up in OF as tasks (via the +omnifocus email).

Everything is great, [B]except[/B] for one detail:
OmniFocus will add as a Note the title of the iCal event.
This is a big deal to me because I use notes exclusively for tasks that have actual notes I need to read. The way it is now, it annoys me to open a note only to find out it is not really a note but some iCal debris.

I realize this is the way iCal emails the alarms (it copies into the body of the email the title of the event). So my question is:

Is there some kind of script that will either, prevent iCal from emailing the events like that, or one that removes that text/note from OmniFocus, or even from the email itself just before OF grabs it?

Thank you in advance.

whpalmer4 2011-07-19 03:07 PM

1 Attachment(s)
Here's a little script which will strip the notes from the selected rows. Note that selecting a project without selecting its contained actions will only strip the note from the project itself.

FMiguélez 2011-07-20 01:22 AM

Hi, whPalmer4.

You are giving me hope!

Since I am just starting to find out scripting, I didn't know what to do with yours...
I know it works because I could call the script from the Scripts menu in the Menu bar. So I just select the tasks whose notes I want deleted, select the script from the menu and voila!

Now, while it works, I would need something more sophisticated if I want to really automate this.
I would like to automatically erase the notes from the tasks that go into OF via a "+omnifocus" email.

I tried adding another Run Script command in Mail's rule (after the default OF script), but rules only admit one script.
I tried placing your script on another rule immediately below, but it didn't work (obviously).

I tried opening OF's default Mail Action applescript and pasting at the end of it your script. It was a looooooooong newbie shot, and it didn't work either (no wonder).

I guess what I'd need to do is to add to the OF's Mail Action Script a section where those tasks get selected and pass that selection to your script. That would do what I want automatically, yes?

Is there a way to join those 2 scripts into one?
Would that require lots of extra code, or a simple joining routine could work?

I've been messing around with the scripting dictionaries. This is not the kind of thing one learns in an evening... I'd probably need months of study to learn to make my own scripts.
I will schedule some time every week for learning this little by little.

In the mean time, am I in the right path?
Any pointers or suggestions I could research?

Thank you : >)

whpalmer4 2011-07-20 10:24 AM

You didn't pay for the deluxe version? :-)

Okay, if you really to automate this, this appears to work. Make a new rule in Mail which appears above your existing OmniFocus rule(s). Have it only run on messages sent by iCal, which it appears you can determine by looking to see if the subject begins with "Alarm - ". The rule then runs the following script instead of the one inside the OmniFocus application, and strips away the content of the message before handing it to OmniFocus. It's a trivial change to the OmniFocus version of the script, but you're accepting responsibility for making sure that you track any changes they might make to the original. You could of course replace the original, but that means you have to repeat the process each time you update OmniFocus.

Here's a snapshot of the rule I used to test that the script didn't break any existing functionality (except, of course, the ability to send a message which starts with "Alarm - "!). You could use something like this instead of the rule installed by OmniFocus if you are comfortable that everything still works with this change in place.

[URL=http://imageshack.us/photo/my-images/64/screenshot20110720at110.png/][IMG]http://img64.imageshack.us/img64/1953/screenshot20110720at110.png[/IMG][/URL]




The edited version of the script appears below. Make sure you set up your rule to point to wherever you've saved the compiled version.

[code]
-- Copyright 2007 The Omni Group. All rights reserved.
--
-- $Header: svn+ssh://source.omnigroup.com/Source/svn/Omni/branches/OmniFocus/1.9.x/OmniGroup/Applications/OmniFocus/App/Preferences/MailAction.applescript 110059 2009-03-12 04:33:13Z kc $

using terms from application "Mail"
-- Trims "foo <foo@bar.com>" down to "foo@bar.com"
on trim_address(theAddress)
try
set AppleScript's text item delimiters to "<"
set WithoutPrefix to item 2 of theAddress's text items
set AppleScript's text item delimiters to ">"
set MyResult to item 1 of WithoutPrefix's text items
on error
set MyResult to theAddress
end try
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
return MyResult
end trim_address


on process_message(theMessage)
tell application "OmniFocus"
log "OmniFocus calling process_message in MailAction script"
end tell
-- Allow the user to type in the full sender address in case our trimming logic doesn't handle the address they are using.
set theSender to sender of theMessage
set trimmedSender to my trim_address(theSender)
tell application "OmniFocus"
set AllowedSender to allowed mail senders
if AllowedSender does not contain trimmedSender and AllowedSender does not contain theSender then
return
end if
end tell

set theSubject to subject of theMessage
set singleTask to false
if (theSubject starts with "Fwd: ") then
-- Whole forwarded messages shouldn't split.
set singleTask to true
set theSubject to text 6 through -1 of theSubject
end if

set theText to theSubject & return & content of theMessage
if (theSubject starts with "Alarm - ") then
-- iCal reminder, strip off unwanted message body
set theText to theSubject & return
end if
tell application "OmniFocus"
tell default document
parse tasks with transport text theText as single task singleTask
end tell
end tell
end process_message

on perform mail action with messages theMessages
try
set theMessageCount to count of theMessages
repeat with theMessageIndex from 1 to theMessageCount
my process_message(item theMessageIndex of theMessages)
end repeat
on error m number n
tell application "OmniFocus"
log "Exception in Mail action: (" & n & ") " & m
end tell
end try
end perform mail action with messages
end using terms from



[/code]


The added lines are simply:

[code]
if (theSubject starts with "Alarm - ") then
-- iCal reminder, strip off unwanted message body
set theText to theSubject & return
end if
[/code]

FMiguélez 2011-07-21 06:42 PM

.

This is GREAT!

I have to tell you I am VERY happy. These are a few of the reasons, all related:

- Doing what I wanted IS possible

- You were kind enough to come up with a great and easy solution for me and posted it : >)

- I started getting into scripts (watched a bunch of tutorials) and found out how powerful they can be. They are approachable and I could learn them well.

- I found the solution you offered me on my own by "brute force" (I spent the whole night reading/watching tutorials about scripts and trying out things in Mail and iCal. I was trying to change the way iCal emails the messages. None of that worked, but then, with the little basic scripting knowledge I acquired throughout the night, I opened OF's script instead and found the lines:

[I]set theText to theSubject & return & content of theMessage[/I]

It was the only place where I could see some kind of reference to the mail message. At first I tried deleting everything after the first [I]&[/I] sign... It didn't work.
So I tried only deleting the [I]& content of theMessage[/I] part and leaving the rest alone. It worked!!

Not as elegant as your solution, and it took me the [I]full night[/I] to discover it, but the key thing was always in that little line of code.

Obviously, your solution is more sophisticated and better implemented. But you've inspired me to continue learning about scripting.
I'll approach it as learning a new language (so I'll speak spanish -my native language- English and [I]scripting[/I] ! ).


Palmer, than you so much for your help!
I hope I can repay it one day by helping others when I become an expert OF user (you've certainly been contributing to this!).

Also, I will post here a few of the video tutorials I watched yesterday. They were extremely helpful (at an introductory level) and made me understand how it all fits together. Hopefully someone will find them useful.

I'll do that ASA get home.

Again, thank you very much!

Brian 2011-07-22 01:42 PM

That's pretty awesome, Bill - thanks. :-)

FMiguélez 2011-07-26 08:57 AM

Hello.

These are some of the sources that are helping me get started with scripting.

They are ultra-simple and basic for most of you, but if there is a beginner, like me, who is wondering about scripts, they could be helpful.

This is a great intro tutorial by an Apple guru:
[url]http://www.macosxautomation.com/applescript/video/intro-seminar.html[/url]

Also, this iTunes podcast is very nice. It's too general, but it helps giving a starting point:
It's called: Mac Automation Made Simple, by Ben Waldie

I am currently reading this too:
[url]http://macosxautomation.com/applescript/firsttutorial/index.html[/url]



I am trying to make the discussed script of this thread smarter.
I'll post my resutls (if I can figure it out! )

: >)

Cheers!


All times are GMT -8. The time now is 12:59 PM.

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