Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: jumpstart me with the scripting bridge



Christopher Nebel wrote:

[[bb textDocuments] addObject:doc];


I'm not familiar with BBEdit's dictionary, but what if you changed this to:
[bb addObject:doc];

That won't work, because bb is the application itself, which means it isn't an array. Try using -insertObject:atIndex: instead.

Using -insertObject:atIndex:, e.g.:

	#!/usr/bin/python

	import ScriptingBridge as sb

bb = sb .SBApplication.alloc().initWithBundleIdentifier_('com.barebones.bbedit')

	c= bb.classForScriptingClass_("text document").alloc().init()

	bb.textDocuments().insertObject_atIndex_(c, 0)


only works if BBEdit already has one or more documents open, otherwise an error occurs for fairly obvious reasons:



Traceback (most recent call last):
File "/tmp/tmpscript", line 9, in <module>
print bb.textDocuments().insertObject_atIndex_(c, 0)
objc.error: NSGenericException - Apple event returned an error. Event = 'core'\'crel'{ 'kocl':'TxtD', 'insh':'insl'{ 'kobj':'obj '{ 'want':'TxtD', 'from':'null'(), 'form':'indx', 'seld':1 }, 'kpos':'befo' } }
Error info = {
ErrorNumber = -1708;
}



For comparison, here's the AppleScript version which works just fine for all cases:


	tell application "BBEdit" to make new text document


and here's the py-appscript equivalent, which also works just fine for all cases:


	from appscript import *

	app('BBEdit').make(new=k.text_document)


The objc-appscript equivalent will be:

BBApplication* bb = [[BBApplication alloc] initWithName: @"BBEdit.app"];

	BBReference *doc = [[[bb make] new_: [BBConstant textDocument]] send];


although I haven't finished testing objc-appscript under Leopard so can't vouch for it working there yet. (Although it works just fine - caveat its alpha nature - on Tiger.)



When you say "addObject", Scripting Bridge has to send an event to the application to do that. The problem is that there are at least three different ways to express that (with a position, without a position, and with a container; more if you count the different ways of expressing a position), and a lot of applications only understand one of them. We went with the one that all Cocoa apps understand ("...at end of..."), and there's no way to override that. [1]

Defective by design, in other words.

has
--
"Those that fail to learn from history, are doomed to repeat it." -- Winston Churchill


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-implementors mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-implementors/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.