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

 
Problems using Scripting Bridge and OmniFocus Thread Tools Search this Thread Display Modes
I'm trying to automate stuff with OmniFocus with the scripting bridge.

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

#!ruby

require 'osx/cocoa'

include OSX
OSX.require_framework 'ScriptingBridge'

omnifocus = SBApplication.applicationWithBundleIdentifier_("co m.omnigroup.OmniFocus")

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

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

# this also causes a bus error
omnifocus.documents()[0].projects().insertObject_atIndex_(proj,0)


I get this error

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?
 
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
 
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?

Thanks,

Carl
 
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
 
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:

Code:
#!/usr/bin/ruby

require 'rubygems'
require 'rbosa'

of = OSA.app '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.
 
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.)
 
Have you seen Matt Neuburg's introduction to rb-appscript, entitled Replacing Applescript with Ruby ?
 
A simular problem is discussed here (with Python syntax)
 
Hi 2shortplanks,
Did you try Matt Neuburg's introduction to rb-appscript, entitled Replacing Applescript with Ruby? How did that work out for you?
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting bridge: crash when trying to get child tasks of a task amorya OmniFocus Extras 8 2013-11-10 06:00 AM
Scripting Bridge & NSColor pixel OmniGraffle General 0 2009-12-07 12:19 PM
Problem Using Scripting Bridge and OmniGraffle pixel OmniGraffle General 1 2009-12-03 09:52 AM
Scripting Bridge & OOP namedStyles oopFan AppleScripting Omni Apps 0 2008-11-03 03:46 PM
Export issue / Modify the selection in a Document via AppleScript / Scripting Bridge Scifer_2008 OmniGraffle General 0 2008-10-08 07:06 AM


All times are GMT -8. The time now is 04:32 AM.


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