Re: jumpstart me with the scripting bridge
Subject : Re: jumpstart me with the scripting bridge
From: has <email@hidden >
Date: Thu, 8 Nov 2007 20:25:47 +0000
Delivered-to: email@hidden
Delivered-to: email@hidden
Hey,
By way of an addendum, here's an interesting observation:
We are told that the following:
[<ref> addObject: <class instance>]
is equal to:
make new <class> at end of every <class> of <ref>
and any application that fails to understand this particular form is
pretty much stuffed.
For example:
from ScriptingBridge import *
textedit =
SBApplication.alloc().initWithBundleIdentifier_('com.apple.textedit')
newclass = textedit.classForScriptingClass_(u'document').alloc().init()
textedit.documents().addObject_(newclass)
yields:
AE2000 (981): Received an event:
------oo start of event oo------
{ 1 } 'aevt': core/crel (i386){
return id: 64946178 (0x3df0002)
transaction id: 0 (0x0)
interaction level: 112 (0x70)
reply required: 1 (0x1)
remote: 0 (0x0)
for recording: 0 (0x0)
reply port: 15375 (0x3c0f)
target:
{ 1 } 'psn ': 8 bytes {
{ 0x0, 0x68068 } (Python)
}
fEventSourcePSN: { 0x0,0x68068 } (Python)
optional attributes:
< empty record >
event data:
{ 1 } 'aevt': - 2 items {
key 'kocl' -
{ 1 } 'type': 4 bytes {
'docu'
}
key 'insh' - <--- insertion location = end
of every document
{ 1 } 'insl': - 2 items {
key 'kobj' -
{ 1 } 'obj ': - 4 items {
key 'want' -
{ 1 } 'type': 4 bytes {
'docu'
}
key 'from' -
{ -1 } 'null': null descriptor
key 'form' -
{ 1 } 'enum': 4 bytes {
'indx'
}
key 'seld' -
{ 1 } 'abso': 4 bytes {
'all '
}
}
key 'kpos' -
{ 1 } 'enum': 4 bytes {
'end '
}
}
}
}
------oo end of event oo------
or, in plain AppleScript-ese:
tell application "TextEdit" to make new document at end of every
document
However, if I say:
from ScriptingBridge import *
finder =
SBApplication.alloc().initWithBundleIdentifier_('com.apple.finder')
newclass = finder.classForScriptingClass_(u'folder').alloc().init()
finder.folders().addObject_(newclass)
I get:
AE2000 (928): Received an event:
------oo start of event oo------
{ 1 } 'aevt': core/crel (i386){
return id: 70844416 (0x4390000)
transaction id: 0 (0x0)
interaction level: 112 (0x70)
reply required: 1 (0x1)
remote: 0 (0x0)
for recording: 0 (0x0)
reply port: 42803 (0xa733)
target:
{ 1 } 'psn ': 8 bytes {
{ 0x0, 0x2 } (Finder)
}
fEventSourcePSN: { 0x0,0x2 } (Finder)
optional attributes:
< empty record >
event data:
{ 1 } 'aevt': - 2 items {
key 'kocl' -
{ 1 } 'type': 4 bytes {
'cfol'
}
key 'insh' -
{ -1 } 'null': null descriptor
}
}
------oo end of event oo------
along with a new folder on my desktop; which is actually a bit ironic
as if I try to say:
tell application "Finder" to make new folder at end of every folder
then I get a Finder error as it expects an object specifier, not an
insertion location, for the 'make' command's 'at' parameter...
something which pretty much every AppleScripter already knows, of
course.
So it looks as if Apple already knew that -addObject:'s approach was
defective because it broke on *Finder*, no less, and had to hardcode a
special, Finder-specific exception into Scripting Bridge to avoid
embarrassing themselves.
has
--
http://appscript.sourceforge.net
http://rb-appscript.rubyforge.org
_______________________________________________
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.