Working with ScriptingBridge
Joni Orponen <[email protected]> Thu, 13 Jul 2017 15:10:50 +0200
| Newsgroups | gmane.comp.python.apple |
|---|---|
| Message-ID | <CA+LW3i1aM9Pe0TdBSy_U-XzdPkS_H9DD8swrpA5P=2KUxp+hzw@mail.gmail.com> |
Hello,
I've been following along the SBSendEmail example from Apple.
https://developer.apple.com/library/content/samplecode/SBSendEmail/Introduction/Intro.html
The same should be able to be done via pyobjc as well. The alloc init cycle
of the outgoing message object yields me a Python future object. Example
code below:
from ScriptingBridge import SBApplication
apple_mail = SBApplication.applicationWithBundleIdentifier_(
'com.apple.mail')
apple_mail_message_class = apple_mail.classForScriptingClass_(
'outgoing message')
apple_mail_message = apple_mail_message_class.alloc().initWithProperties_({
'subject': 'foo',
'content': 'bar',
})
Only alloc()ing the object yields an ephemeral pseudo-SB object as improper
SB use does.
>>> apple_mail_message = apple_mail_message_class.alloc()
>>> apple_mail_message
<MailOutgoingMessage objective-c instance 0x7fc0586d24c0>
>>> apple_mail_message.subject()
>>> apple_mail_message.subject()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: cannot access attribute 'subject' of NIL
'MailOutgoingMessage' object
>>> apple_mail_message
<MailOutgoingMessage objective-c instance 0x0>
My understanding of what is going here is that interacting with it once
makes it go away as its retain count is 0 in the Obj-C VM.
The future object contains its properties in its repr().
>>> apple_mail_message
<future MailOutgoingMessage with properties {
content = bar;
subject = foo;
}>
>>> type(apple_mail_message)
<objective-c class SBProxyByClass at 0x7fffa69f9fe0>
So, how to work with these future objects? Or am I doing something
fundamentally wrong in how I'm trying to chase the obj-c example?
--
Joni Orponen
_______________________________________________
Pythonmac-SIG maillist - [email protected]
https://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG