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

RubyOSA Thread Tools Search this Thread Display Modes
Hi all, I'm very new here. I search around the forum (and the Internet) for some good RubyOSA resources. But I've come up short. Currently, I'm working on some custom scripts to extract information from Trac and automatically dumping tickets into my OmniFocus project. The scraping part is fairly easy w/ Ruby. And, I'm not too familiar w/ either Applescript or Cocoa framework. So, I thought I'd poke around RubyOSA and see what I can come up with.

So far I managed to get at various Folders, Projects and Tasks. By getting at it I mean reading its content. But I'm having some trouble trying to create some of those objects and saving them back to OmniFocus. Does anybody know how objects (Folder, Project, Task etc.) creation works with OmniFocus at least in terms of OSA? Also, I love to know if there's a search API built-in? Just glancing through the RDoc generated by RubyOSA, I couldn't see an obvious one. :confused: Any help is greatly appreciated. OH, and if I figure this out I'd happily share the script w/ anyone who's interested.
You'll find lots of Applescript samples on this forum and linked from it. I haven't used RubyOSA, but I assume the RDoc is essentially the same as the Applescript dictionary for the application. You might see if comparing the RDoc to the AS dictionary (in ScriptEditor) gives you a path for converting the sample Applescripts here into RubyOSA.

I would recommend rb-appscript over RubyOSA at this point. We tried RubyOSA and ran into enough roadblocks (entered in the RubyForge tracker) that we switched.

Here is an example of creating an inbox item using rb-appscript:

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
require 'getoptlong'

def first_of_class(doc, str, cls)
  # Use the 'complete' command to perform a ranked match of the given string and AppleScript class
  # This uses the same code as the completion cell in the outline in OmniFocus.
  matches = doc.complete(str, :as => cls, :maximum_matches => 1)
  matches.size > 0 || die("No #{cls} found matching '#{str}'!")
  # We want the entry in the element array with the identifier that is in the returned match record.
  # Note the :id_ key for getting the identifier out of the record.  A few places have munging like this to avoid conflicts with Ruby methods.
  element_id = matches[0][:id_]

  # Construct the element name from the class name based on the default rule.  Might be some rb-appscript API for getting the plural terminology for a class...
  element_name = (cls.to_s + "s").to_sym
  # The proxy representing the element.  This doesn't *get* the element, just gives us an object specifier for it.
  element_array = doc.send(element_name)
  # Build the object specifier for the entry in the array.  We could call #get to actually get the object, but we are just going to use it as a specifier anyway.

app =["FOCUS_PATH"] || "OmniFocus")
doc = app.default_document
properties =
  [ "--project", "-P", GetoptLong::REQUIRED_ARGUMENT ],
  [ "--context", "-C", GetoptLong::REQUIRED_ARGUMENT ],
  [ "--title", "-T", GetoptLong::REQUIRED_ARGUMENT ],
  [ "--note", "-N", GetoptLong::REQUIRED_ARGUMENT ]
  ).each do |option, argument|
    case option
    when "--project"
      properties[:assigned_container] = first_of_class(doc, argument, :project)
    when "--context"
      properties[:context] = first_of_class(doc, argument, :context)
    when "--title"
      properties[:name] = argument
    when "--note"
      properties[:note] = argument
      fail "Unrecognized option '#{option}'"
doc.make(:new => :inbox_task, :at => doc.inbox_tasks.end, :with_properties => properties)
CTO, The Omni Group

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
setting Text properties using Ruby appscript or RubyOSA Joe.Hocker AppleScripting Omni Apps 1 2009-02-14 12:20 AM

All times are GMT -8. The time now is 12:31 AM.

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