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

 
Scripting bridge: crash when trying to get child tasks of a task Thread Tools Search this Thread Display Modes
I'm using the Scripting Bridge to control OmniFocus. If I write this code:

Code:
			for (OFTask *task in project.rootTask.flattenedTasks)
			{
				NSLog(@"Task %@", task.name);
			}
I get a crash. "project" is a valid OmniFocus project (I can log its name etc). Calling "project.rootTask" works fine. But when I ask for "flattenedTasks", I get this crash:

Code:
2012-07-07 15:17:27.635 OmniReviewer[18623:403] -[SBObject classForCode:]: unrecognized selector sent to instance 0x7fd539607ea0
The same thing happens if I just ask for "tasks" rather than "flattenedTasks".

Does anyone have any idea why I can't seem to get the child tasks of a task?
 
Have you tried project.flattenedTasks ?

(The root task of project is a rather strange and special case, it is really a reference to the project itself A project is just a decorated task)
 
Sadly, there's no such property. The only things that have a "flattenedTasks" property are tasks and documents.

The comment for the rootTask property of a project says "The root task of this project, holding the project's name, note, dates and child tasks.", which is what led me to think you're meant to do it that way.
 
Curious ...

That's not what theory would predict you can certainly access the flattened tasks of a project through the Applescript dictionary ...

--
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-07-07 at 16.24.07.png
Views:	316
Size:	33.4 KB
ID:	2453   Click image for larger version

Name:	Screen Shot 2012-07-07 at 16.21.02.png
Views:	323
Size:	64.9 KB
ID:	2454  
 
A full llist of the classes from which flattened task elements can be accessed:



--
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-07-07 at 16.38.56.png
Views:	531
Size:	21.1 KB
ID:	2455  
 
It's odd: the Scripting Bridge thing that generates headers didn't generate any "tasks" property on "project".

So I tried doing it manually:

Code:
SBElementArray *arr = [project elementArrayWithCode:'FCac'];
Sadly that gave the same error as I was originally experiencing :(
 
A summary to be found in this interesting thread (to which Ken Case recently contributed a perspective), is that Scripting Bridge is:
"fundamentally defective by design and breaks to some degree or other on pretty much all apps"
As you will read in the thread (if you haven't seen it already), all of this kind of non-Applescript scripting is getting increasingly fragile at the moment. The Ruby route described there by Matt Neuburg (fetching the dictionary through sdef instead ascr/gdte) seems to be the most robust for now (apart from Applescript itself).

https://github.com/mattneub/appscript
http://www.apeth.com/rbappscript/00intro.html

It's still not clear what the mid-term effects of sand-boxing on the scriptability of OS X will really be. To quote the phrase used by Matt Neuburg, again in that thread, it may still be a bit early get too "happy-clappy" about the impact of sandboxing on automating work-flows and integrating apps into larger tool-chains... )

--

Last edited by RobTrew; 2012-07-08 at 12:22 AM.. Reason: Added Ruby appscript links
 
I sidestepped the problem!

If I do

Code:
[[rootTask propertyWithCode:'FCft'] get]
rather than doing elementArrayWithCode, it works and returns me an array of tasks. The latter causes the crash, and that seems to be what the auto-generated headers were doing.
 
Just in case anyone was following along at home, I believe this was an Apple bug and is fixed in Mavericks.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting Bridge & NSColor pixel OmniGraffle General 0 2009-12-07 11:19 AM
Problem Using Scripting Bridge and OmniGraffle pixel OmniGraffle General 1 2009-12-03 08:52 AM
Scripting Bridge & OOP namedStyles oopFan AppleScripting Omni Apps 0 2008-11-03 02:46 PM
Export issue / Modify the selection in a Document via AppleScript / Scripting Bridge Scifer_2008 OmniGraffle General 0 2008-10-08 06:06 AM
Problems using Scripting Bridge and OmniFocus 2shortplanks OmniFocus Extras 8 2008-08-09 09:35 PM


All times are GMT -8. The time now is 03:01 AM.


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