[Pythonmac-SIG] appscript and Office 2011, not working?

has hengist.podd at virgin.net
Sun Feb 13 19:12:32 CET 2011


Christian Prinoth wrote:

> Just upgraded to Office 2011, and it appears appscript is not working
> correctly with Excel 2011.
>
> If I do the following:
>
> app(u'/Applications/Microsoft Office 2011/Microsoft
> Excel').ranges[u'B2'].value()
>
> I get:
>
> AttributeError: 'Property' object has no attribute 'byname'
>
> while issuing the corresponding command in Applescript editor works
> perfectly:

Wild guess: Excel's dictionary defines both a 'ranges' property and a
'range' class (plural 'ranges'). AppleScript can just about deal with
that sort of ambiguity as the compiler can determine from context if a
'ranges' keyword is being used as a property name or element name.
Appscript doesn't have that luxury, so has to favour one
interpretation or the other; in this case, the former. If you need it
to go the other way, you'll need to drop down to the aem API
(equivalent to using chevron syntax in AS); something like:

app('Microsoft Excel').AS_newreference(aem.app.elements('xxxx'))['B2'].value()

You'll need to use ASDictionary to export the Excel dictionary as
plain text in order to look up the correct four-char code to use in
the aem reference.

I won't bother suggesting you file a bug report on Excel - feel free
to do so, but I don't imagine the developers will want to change
anything as long as it's working in AS (no small achievement itself).
It's not really their fault anyway: Apple have never provided an
adequate spec for application developers to follow, never mind
validation tools to check their application dictionaries are formally
correct. So the best that any application developer can realistically
do is test that their app works okay with AS, as that's the de facto
standard. Appscript tries to be quirk-for-quirk compatible with AS to
minimize these sorts of compatibility problems, but there are limits
to what it can reasonably achieve and sometimes you just have to fall
back to the lower-level APIs to deal with such issues.

HTH

has


More information about the Pythonmac-SIG mailing list