The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

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

Jott 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 called 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
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)
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. :)

Last edited by snarke; 2008-10-13 at 09:15 PM..
 
this sounds really cool, but I'm not sure how to place ruby script.
 
Yeh it does sounds cool! I need it! But i live in europe:mad:
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apple Mail Jott to OmniFocus AppleScript duetjohn OmniFocus Extras 19 2009-08-12 03:26 PM
Jott or Email to Omnifocus RJG OmniFocus Extras 2 2008-11-17 04:48 PM
Jott -> Mail.App -> OmniFocus jrapp111 OmniFocus Syncing 3 2008-08-13 07:43 PM
Jott integration? sag OmniFocus for iPhone 5 2008-07-22 11:52 AM
Jott to OmniFocus Script posted MB_UST OmniFocus Extras 3 2008-01-03 05:07 AM


All times are GMT -8. The time now is 03:49 PM.


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