• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Script Objects, Inheritance and Delegation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script Objects, Inheritance and Delegation


  • Subject: Re: Script Objects, Inheritance and Delegation
  • From: Paul Berkowitz <email@hidden>
  • Date: Tue, 13 Apr 2004 18:19:56 -0700

On 4/13/04 5:24 PM, "David Weiss" <email@hidden> wrote:

> If I wanted to write an automated test system with AppleScript I would
> use the following template for each of my test scripts:
>
> property parent : application "eXodus"
> property name : "Some nice test name"
> property target : {"Microsoft Word", "Microsoft Entourage", "Microsoft
> Excel", "Microsoft PowerPoint", "MSN Messenger", "Virtual PC"}
> property testCaseID : 20324
>
> on run
> startAutomation for me
> with timeout of my standardTimeout seconds
> try
> if preTest() then mainTest()
> postTest()
> on error errorMessage number errorNumber
> logTestError(errorMessage, errorNumber)
> end try
> end timeout
> set theScriptResult to scriptResult()
> quit
> return theScriptResult
> end run
>
> on mainTest()
>
> -- your test code goes here
> tell my XLib to LogComment("test")
>
> end mainTest
>
> ---
>
> This could be very useful. This script template would inherit from the
> AppleScript application named eXodus. Special cases could override the
> standard preTest() and postTest() if needed and continue to delegate
> the standard functionality. The function "startAutomation for me" would
> load 40 or so different script objects into properties in the eXodus
> application. The libraries could have access to the script's target
> information.
>
> Questions:
>
> 1. Why can't I call a function in one of the loaded libraries like
> this: XLib's LogComment("My comment text") I know tell my XLib to
> LogComment("test") works, but why can't I use the possessive form?

You forgot 'my' in the first case:

my XLib's LogComment("My comment text")

Does that not work?

> 2. In any of the loaded libraries, (that also inherit from the eXodus
> application) I can't call any of the other functions. For example, if I
> loaded a library named "XLib" and in it were two functions like so:



>
> on LogPass(passText)
> say "LogPass"
> writeToFile(passText)
> end LogPass

my writeToFile(passText)

You forgot 'my' again: from within another handler you need to refer to the
script's (my) otherHandler(). If you're not going from child to parent (not
calling writeToFile from the child) not calling a handler in the same script
file, you'll have to specify which script it belongs to instead of 'my'.
>
> and
>
> on writeToFile(theText)
> display dialog theText
> end writeToFile
>
> I will hear "LogPass" but I'll get an error when I try to call
> writeToFile() In order to call another function in the same script
> object I must us this syntax:
>
> tell my parent's XLib to writeToFile(theText)

What happens with

my writeToFile(theText)

?
>
> and when accessing "my own script object" properties I must us this
> syntax:
>
> my parent's Xlib's standardTimeout

my standardTimeout
>
> 3. In the eXodus applescript I define a property named target which is
> missing value. The script overrides this property and defines it with a
> list. Yet when I try to access the target property from the eXodus
> application script I get only missing value! This is why
> startAutomation has a parameter "me" which allows me to set these
> properties for use by the other libraries. Since the script is over
> ridding the properties, why aren't they overridden?

When you later " try to access the target property from the eXodus
application script" are you loading it again? If so, you're getting a brand
new instance of eXodus in memory, an instance that doesn't know anything
about the previous overriding. Instead, define a variable, or a property
initialized to missing value, in the calling script to load eXodus the first
time (so the property will now be a script object of the calling script) and
later do everything with the script property (script object).
>
> Why oh why? This inheritance stuff looked sooo useful, but then I seem
> to loose all the script object goodness when I inherit! Does anyone
> know why this is?
>
> David Weiss
>
> P.S. I've poured over Chapter 9 of the AppleScript Language Guide long
> enough.

What you want is Matt Neuburgs's " AppleScript: The Definitive Guide": he's
_really_, really good on this stuff. there are several chapters on it.


--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Script Objects, Inheritance and Delegation (From: David Weiss <email@hidden>)

  • Prev by Date: Re: [OT] network time servers
  • Next by Date: Re: Script Objects, Inheritance and Delegation
  • Previous by thread: Script Objects, Inheritance and Delegation
  • Next by thread: Re: Script Objects, Inheritance and Delegation
  • Index(es):
    • Date
    • Thread