[Pythonmac-SIG] Announce: OSATools

Bill Bedford billb@mousa.demon.co.uk
Wed, 4 Dec 2002 11:59:51 +0000


At 1:37 am -0800 04/12/02, Paul Berkowitz wrote:

>On 12/4/02 1:15 AM, "Michael J. Barber" <mjb@uma.pt> wrote:
>
>> On Tuesday, December 3, 2002, at 10:44  PM, Bill Bedford wrote:
>>
>> [my example using AE snipped]
>>> It seems to me that.....
>>>
>>> folderList = ['/Applications', '/Library']
>>> countList = []
>>> for f in dirFolder:
>>> countList.append(len(os.listdir(f)))
>>> return countList
>>>
>>> Is not only much more succinct, but is much easier to read.
>>>
>> That's very true. Not much of an example for how to construct an
>> AppleScript-style tell block, though, is it? ;)
>>
>> Divorced from a real problem, it's a bit difficult to find a good
>> example that is interesting, succinct, and (perhaps most importantly)
>> uses an application that everyone has. Any suggestions?
>
>
>AppleScript will always be more verbose than Python - that's part of its
>"English-like syntax". And Perl is more succinct than Python. That's how it
>is, and less comprehensible.  Best to use an AS example in an application,
>which other languages can't touch. Everyone in OS 10.2 can do this:
>
>--------------
>
>tell application "Address Book"
>    set joeBlow to make new person with properties {first name:"Joe", last
>name:"Blow"}
>    tell joeBlow to make new email at end of emails with properties
>}
>    save addressbook
>end tell
>
>
>----------------
>
>Convert that into Python/OSA.
>

Without having seen the Address Book dictionary it should be something like:

import Address_Book
ab = Address_Book.Address_Book
ab.make(Address_Book.person('joeBlow'),
		Address_Book.properties({'first_name':"Joe", 'last_name':"Blow"}))
ab.make(Address_Book.email(-1),
		Address_Book.person('joeBlow'),
		Address_Book.properties({{label:"home",
value:"jblow@earthlink.com"}))
ab.save_addressbook ()

Python interfaces not with apple script but with the underlying
AppleEvents so there is no need for 'Tell Blocks"


-- 

Bill Bedford

He said no more is no less than it is
if in the future we live in the past