The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Jott 2 OmniFocus (http://forums.omnigroup.com/showthread.php?t=10217)

snarke 2008-10-13 08:13 PM

Jott 2 OmniFocus
 
Well, I'm not sure I have all the bugs worked out yet, but it seems to be working. So why not share?

[URL="http://www.jott.com"]Jott[/URL] is a new company that's offering a pretty nifty speech-to-text service. I have them on speed-dial on my cell phone, so if I'm out running errands or such, and I suddenly think of a "to do" item, I punch the button, and tell the JottBot something like "Add 'Spore' to my Christmas gift list."

During beta-testing, the result would be an email to me with my message transcribed. For people with paid Jott accounts, that's still how it works.

But I'm a cheapskate. So now I get an email with a link to the Jott website where I can pick up my message.

I'm cheap, but clever. So, attached is the script I'm working on that, when triggered by a Mail rule, will extract the URL from the message, log onto the Jott website, retrieve the message, and put it in my OmniFocus inbox.

Unfortunately, this isn't a simple AppleScript. It could probably be rewritten as such, but I would have had to have hand-coded piles and piles of stuff which is trivial in Ruby. So the real work's done by a Ruby script, which has to be [I]called[/I] by an AppleScript, since currently there doesn't appear to be any way (or at least any reasonably simple way) to create a handler in Ruby.

Ah, but it's worse than that. The Ruby script depends on "rb-appscript" and "mechanize," which I don't think are currently part of the default installation. They're easy enough to add as gems, but if you don't know how to do that, then this script might not be worth your time to try to use anyway . . .

Anyway, the AppleScript part is based on Omni's own Mail Action script. It has the 'perform mail action' handler, extracts the URL from the message in question, and passes it to the Ruby script. I put both this script and the rubyscript in my mail script folder. This script contains a semi-hard-coded path to the Ruby script.

[code]
property rubyscript : (path to scripts folder from user domain as text) & "applications:mail:Jott.rb"

using terms from application "Mail"
on perform mail action with messages theMessages
try
ProcessMessage(theMessages)
on error m number n
tell application "OmniFocus"
log "Exception in Jott Mail action: (" & n & ") " & m
end tell
end try
end perform mail action with messages

on ProcessMessage(theMessage)
repeat with CurrentMessage in theMessages
try
set Pars to paragraphs of (content of CurrentMessage)
repeat with currentPar in Pars
if currentPar begins with "http://" then
do shell script "/usr/bin/ruby " & quoted form of (POSIX path of rubyscript) & " " & quoted form of (currentPar as text)
delete CurrentMessage
end if
end repeat
on error m number n
tell application "OmniFocus" to log "Exception in Jott Mail action: (" & n & ") " & m
end try
end repeat
end ProcessMessage
end using terms from
[/code]

The ruby script uses Mechanize to simplify opening the Jott site, filling out the logon form, and retrieving the message. After parsing the text from the page, appscript lets us insert the message into OmniFocus. There's a place at the beginning to embed one's Jott site logon info.

[CODE]require 'rubygems'
require 'appscript'
require 'mechanize'

JottAccount=[:phonenumber=>"mycellnumber", :password=>"mypassword"]

include Appscript

url = ARGV.first

agent = WWW::Mechanize.new
loginpage = agent.get('https://jott.com/login.aspx')
newpage = nil
loginpage.forms.each do |form|
succeeded = form.fields.each do |field|
field.value = JottAccount[:phonenumber] if field.name.match(/PhoneNumber/)
if field.name.match(/Password/) then
field.value = JottAccount[:password]
agent.submit(form, form.buttons.first)
break true
end
false
end
break if succeeded
end
jottpage = agent.get(url)
jotttext = jottpage.forms[0].fields.collect {|f| f.value if f.name.match(/JottText/)}.to_s

app("OmniFocus").default_document.parse_tasks( :with_transport_text => jotttext, :as_single_task => true)

[/CODE]

It occurred to me when posting this that I could eliminate the need for appscript by having the Ruby script return the text of the message, and letting the AppleScript handle the conversation with OmniFocus. However, I think the odds are quite good that either nobody else will use this script in the first place, or somebody else will be willing and able to handle that fairly minor rewrite themselves (and hopefully post the revised version here).

I haven't been sending myself email messages, and the Jott script is new, so I haven't played around much with all the clever tricks you can do in an email message, but I'm using OmniFocus's "parse tasks" command, so they ought to work. If I do start wanting to specify the context, project, due date, or other such magic, I'll probably need to add code to the Ruby script to allow me to use the words "project," "context," and such in my speech, since trying to specify double hyphens, dollar and pound signs when talking to Jott doesn't sound terribly reliable to me. :)

erifneerg 2008-10-27 01:37 PM

this sounds really cool, but I'm not sure how to place ruby script.

mhbheres 2008-11-04 12:46 PM

Yeh it does sounds cool! I need it! But i live in europe:mad:


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

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