The Omni Group Forums

The Omni Group Forums (
-   OmniFocus Extras (
-   -   Problems using Scripting Bridge and OmniFocus (

2shortplanks 2008-01-22 04:18 AM

Problems using Scripting Bridge and OmniFocus
I'm trying to automate stuff with OmniFocus with the scripting bridge.

It's working, but I'm have problems with creating new projects:

[FONT="Courier New"]#!ruby

require 'osx/cocoa'

include OSX
OSX.require_framework 'ScriptingBridge'

omnifocus = SBApplication.applicationWithBundleIdentifier_("com.omnigroup.OmniFocus")

p = { "name" => "Foo" }
Project = omnifocus.classForScriptingClass_("project")
proj = Project.alloc();

# this causes a bus error
# proj.get();

# this also causes a bus error

I get this error

[FONT="Courier New"]travis-2:~ mark$ ruby testscript
ruby: unknown type name "item".
/System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_wrapper.rb:50: [BUG] Bus Error
ruby 1.8.6 (2007-09-24) [universal-darwin9.0]

Abort trap

What am I doing wrong?

RobTrew 2008-01-22 09:40 AM

Haven't used Scripting Bridge, but the problem may be that you need to use a constructor which is a method of the document class.

The applescript analogy would be something like:
[CODE]tell application "OmniFocus"
tell front document
set oProj to make new project
end tell
end tell

Carl Bourne 2008-02-16 05:37 PM

Similar problems
Hi I'm trying to do a similar thing with OmniPlan.

Did you ever get this to work?

Are there any examples on using Ruby with new Leopard scripting bridge?



RobTrew 2008-02-16 11:08 PM

FWIW, ensuring that you use constructors which are methods of the appropriate parent class would look something like this in applescript for Omniplan. The pattern would be analogous in Ruby.

[CODE]tell application "OmniPlan"
set oProj to project of document of window 1

tell oProj
set oTopLevelTask to make new task
end tell

tell oTopLevelTask
set oSubTask to make new task
end tell
end tell[/CODE]

jedediah 2008-02-21 10:38 PM

Can't say I've used the scripting bridge, but I do have a handful of scripts working using the rbosa gem. It maps most applescript stuff to ruby very idiomatically, and I've been very impressed. Quick example from just a few minutes ago:


require 'rubygems'
require 'rbosa'

of = 'OmniFocus'
shopping_list = of.default_document.contexts['Shopping']

I did have to write some functions to make the square bracket notation functional, but overall, it was very easy.

If you do forge ahead with the scripting bridge, I'd love to know what you think of it.

2shortplanks 2008-02-28 12:37 AM

I've actually given up on this whole Scripting Bridge thing. It requires the authors of the application to write their "scripting" in a particular way, something that Omni didn't do with OF.

Not that I'm blaming OF of course - the script bridge authors seem to have chosen an arbitrary standard without communicating this to any application authors. As such, it doesn't seem to work with majority of apps out there, and as such, I'm not going to pay it much more attention until either scripting bridge gets turned into something more compatible or apple do some serious work to convince the authors out there to change the way their "scripting" works (which I doubt they would, as it would probably break a lot of existing scripts if they were to make those changes.)

RobTrew 2008-02-28 09:48 AM

Have you seen Matt Neuburg's introduction to [URL=""]rb-appscript[/URL], entitled [URL=""]Replacing Applescript with Ruby[/URL] ? 2008-08-01 11:57 AM

A simular problem is discussed [URL=""]here[/URL] (with Python syntax)

nanovation 2008-08-09 09:35 PM

Hi 2shortplanks,
Did you try Matt Neuburg's introduction to rb-appscript, entitled Replacing Applescript with Ruby? How did that work out for you?

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

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