PDA

View Full Version : Apple Mail Jott to OmniFocus AppleScript


duetjohn
2008-03-29, 02:46 PM
Howdy,

I've modified the basic AppleScript that comes with OmniFocus so that it pulls the Jott message out of the e-mail. It assumes that a single message is a single task. I even included a link back to the original e-mail. However, the link I put into the note doesn't work quite right.

Does anyone know of a way to put a link into a note processed by "parse tasks"? I include something like "Jott message: message://<1206587236.14269@jott.com>", which is the correct format for the link, but it doesn't automatically appear as a link. Worse yet, when I manually type a space after it, OmniFocus creates two links: "message://" and "1206587236.14269@jott.com". It seems to view the "<" as a separator (which may be correct from an RFC standpoint).

If I instead send the text "Jott message: <message://<1206587236.14269@jott.com>>", I manage to get the "<" included, but it also includes the first "<". The link becomes: "<message://<1206587236.14269@jott.com>".

The script is below if you'd like to try it out.

. John
--
-- Derived from work that is copyright 2007 The Omni Group. All rights reserved.
-- Modified to work specifically with Jott messages.

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)
set theContent to content of theMessage
set messageStart to (offset of "Jott:" in theContent) + 6
set messageEnd to (offset of "Listen" in theContent) - 2
set theSubject to text messageStart through messageEnd of theContent
set theText to theSubject & return & "Jott message: message://<" & message id of theMessage & ">"
tell application "OmniFocus"
tell default document
parse tasks with transport text theText with as single task
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

Bill Van Hecke
2008-04-07, 01:52 PM
Brilliant! I just tested this out with my own Jott and Apple Mail, and it's working great. No more swervy driving whenever I think of something that needs to be in my inbox!

duetjohn
2008-04-07, 03:42 PM
Glad to see that others are finding Jott really cool and useful. I also like being able to quickly and easily send myself a message, especially on the road. It's almost eery to get the message in OmniFocus without seeing it in Mail.

Enjoy!
. John

sponjireggae
2008-04-14, 08:06 AM
Did anyone figure out the fix for the link?

Thanks...

duetjohn
2008-04-14, 08:25 AM
Not that I know of. I reported this issue to Omni, so hopefully they'll fix it in an upcoming release.

akelley
2008-04-20, 12:01 AM
Here's a modifed version that is derived from Curt Clifton's OmniFocus-Mail Links script

-- Derived from work that is Copyright © 2007, Curtis Clifton All rights reserved.
-- Modified to work specifically with Jott messages.

-- If true, then the sender of the message is included in the action's description.
property includeSender : true

property messageSender : "Jott"

on run
tell application "Mail"
set selectedMessages to selection
if ((count of selectedMessages) ≠ 1) then
display alert "Please select a message to be linked to the new action" message "This script creates a new OmniFocus action that links back to a selected message." buttons {"OK"} default button "OK" giving up after 20
return
end if
my process_message(item 1 of selectedMessages)
end tell
end run

using terms from application "Mail"
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 77.1.3.0.97731"
log "Exception in Mail action: (" & n & ") " & m
end tell
end try
end perform mail action with messages
end using terms from

on process_message(theMessage)
tell application "Mail"
set theContent to content of theMessage
set theDate to date sent of theMessage
set messageId to message id of theMessage
end tell

tell application "OmniFocus 77.1.3.0.97731"
set messageStart to (offset of "Jott:" in theContent) + 7
set messageEnd to (offset of "Listen" in theContent) - 3
set taskName to rich text messageStart through messageEnd of theContent
if (includeSender) then
set taskName to taskName & "—" & messageSender
end if
set theDoc to first document
tell theDoc
set propRecord to {name:taskName}
set theTask to make new inbox task with properties propRecord
end tell
tell theTask
set start date to theDate
set note to return & return
tell note
set theURL to "message://<" & messageId & ">"
set linkText to theURL
insert linkText at before first character
set value of attribute "link" of style of paragraph 1 to theURL
end tell
end tell
end tell
end process_message

devn
2008-04-29, 02:30 AM
This doesn't work for me... Expected ',' after the unicode not equals sign, changing it to != doesn't work.

Here's a modifed version that is derived from Curt Clifton's OmniFocus-Mail Links script

Edit: removed the script from the quote, since it just made the page require that much more scrolling to read.

Brian
2008-04-29, 02:21 PM
I don't have jott installed, devn, but I am able to copy the script, paste it into Script Editor, and compile it with no errors. This is on a 10.5.2 machine.

lostianfog
2008-05-07, 11:27 AM
Hi guys-

I was having trouble getting the Omnifocus Mail rule thing to work for me with Jott. I set it to the +omnifocus version, which works with my gmail account. I'd then leave a jott to that address and start the jott with "hyphen hyphen". I'd get the email but the rule wouldn't work--nothing in my OF inbox.

I tried the 2 applescripts above too, but nothing. I know the rule ran because I had it move the message before running the applescript. I'm hopeful somebody can help, with my apologies for being an apparent idiot.

Does OF need to be running for the mail message to work?
If I use one of the scripts in this thread should I turn off the mail rule in the OF pref?
Is there some easy setting thing I'm missing?

thanks

mianwright
2008-05-19, 03:00 PM
I had NEVER used applescript before now. I just copied and pasted into scripteditor and saved it to my documents folder as jotttomail. Set up a rule in Mail to run when email received from notify@jott.com that runs a script and pointed it at the script.

Fanfrickingtastic!

Thanks;)

ArsCerebri
2008-12-17, 12:52 PM
Brilliant! I just tested this out with my own Jott and Apple Mail, and it's working great. No more swervy driving whenever I think of something that needs to be in my inbox!

Sadly, it is not working so well for me. I get worse headers than with the OmniFocus built-in script. Every Inbox item is now titled "voice-to-text message was sent by Jott on behalf of..." and the actual item I want to be listed as the subject is in the item's note, instead.

Any thoughts?

cellmatrix
2009-03-19, 02:26 PM
Jott changed their email template this week, and now no scripts currently work for getting Jott email into omnifocus. I wish I were an applescript guru like Curtis or one of the other talented individuals here, but sadly I am not, nor I am afraid that I ever will find the time to become one.

But if anyone who is facile with applescript could fix this probably simple problem, I know a lot of folks, including me, would greatly appreciate it.

dschaffner
2009-03-21, 04:43 PM
But if anyone who is facile with applescript could fix this probably simple problem, I know a lot of folks, including me, would greatly appreciate it.

*facile*? Nope.

Persistent. Yup.

Changing:

set messageStart to (offset of "Jott:" in theContent) + 7
set messageEnd to (offset of "Listen" in theContent) - 3

To:
set messageStart to (offset of "Jott:" in theContent) + 1
set messageEnd to (offset of "Listen" in theContent) - 4

Seemed to fix things for me.

- Don

cellmatrix
2009-03-23, 08:29 AM
*facile*? Nope.

Persistent. Yup.

Changing:

set messageStart to (offset of "Jott:" in theContent) + 7
set messageEnd to (offset of "Listen" in theContent) - 3

To:
set messageStart to (offset of "Jott:" in theContent) + 1
set messageEnd to (offset of "Listen" in theContent) - 4

Seemed to fix things for me.

- Don

worked great - thanks!

akelley
2009-04-23, 02:00 PM
Here's my revised script that specifies starting and ending points of your message as properties. This way, if Jott decides to change their message format again, you simply change these parameter values to reflect the change in their message format

---------------

-- Derived from work that is Copyright © 2007, Curtis Clifton All rights reserved.
-- Modified to work specifically with Jott messages.

-- If true, then the sender of the message is included in the action's description.
property includeSender : true
-- Start of the message in the body text
property firstmsgchar : 1
--Number of spaces between the last char of the message and the "Listen" link
property lastmsgchar : 5

property messageSender : "Jott"

on run
tell application "Mail"
set selectedMessages to selection
if ((count of selectedMessages) ≠ 1) then
display alert "Please select a message to be linked to the new action" message "This script creates a new OmniFocus action that links back to a selected message." buttons {"OK"} default button "OK" giving up after 20
return
end if
my process_message(item 1 of selectedMessages)
end tell
end run

using terms from application "Mail"
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

on process_message(theMessage)
tell application "Mail"
set theContent to content of theMessage
set theDate to date sent of theMessage
set messageId to message id of theMessage
end tell

tell application "OmniFocus"
set messageStart to firstmsgchar
set messageEnd to (offset of "Listen" in theContent) - lastmsgchar
set taskName to rich text messageStart through messageEnd of theContent
if (includeSender) then
set taskName to taskName & "—" & messageSender
end if
set theDoc to first document
tell theDoc
set propRecord to {name:taskName}
set theTask to make new inbox task with properties propRecord
end tell
tell theTask
set start date to theDate
set note to return & return
tell note
set theURL to "message://<" & messageId & ">"
set linkText to theURL
insert linkText at before first character
set value of attribute "link" of style of paragraph 1 to theURL
end tell
end tell
end tell
end process_message

dryan75
2009-04-28, 04:39 AM
I've never done an apple script. So some help would be appreciated.

I found the script editor. Do I just copy the above, paste it into the "body" field of the editor in the script editor, save it to "my documents", and then it just runs?

If this above process is true, where do I start copying?

From here:
-- Derived from work that is Copyright © 2007, Curtis Clifton All rights reserved.

From here:
property messageSender : "Jott"

Or From Here:
on run

Thanks.
Dan
OS10.5.6
MacbookPro

dryan75
2009-04-28, 01:19 PM
OK, so I got the script to work. Here's my stupid question. Do I have to run the script each time I want it to happen? Or does it create a rule so that when I get a Jott in my inbox it automatically goes to my omnifocus inbox?

Dan

whpalmer4
2009-04-28, 01:59 PM
The idea is that you make a Mail rule which invokes it...

dryan75
2009-05-03, 07:08 PM
Perfect! IT works. Thanks!

FrogProf
2009-08-12, 03:26 PM
Thank you, thank you! My Mail rule was no longer sending my Jotts to OmniFocus and I was clueless about what to do, since I didn't know Jott had changed its format. Now it works again, thanks to you.