• 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: library of subroutines - help needed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: library of subroutines - help needed


  • Subject: Re: library of subroutines - help needed
  • From: Ted Wood <email@hidden>
  • Date: Sun, 17 Dec 2000 00:49:56 -0800

i would like to have a compiled script that uses various "plug in"
scripts in separate compiled script files. in the main script i would
like to have a number of utility routines that could be used by each
of the plugins. i can successfully load and execute the plugins;
however, i haven't been able to figure out the proper syntax in order
to be able to use routines in the main script from the plugins.

my main script is something like:

on run()
...
DoDelete()
...
end run

on DoDelete()
set DeleteScript to (load script file DeleteScriptName)
tell DeleteScript to DoIt()
end DoDelete

on LogMessage( theMessage)
...
end LogMessage

and then the delete plug in might be:

on DoIt()
...
LogMessage("from Delete PlugIn")
...
end DoIt

its the call to LogMessage in the plugin that doesn't seem to work.
i've also tried using:
tell parent to LogMessage("from Delete PlugIn")
and this doesn't work either

is this kind of structure possible? (it seems like it should somehow
be possible.) and if so, how do i get it to work?

thanx,
ken

Hi Ken,

I don't know how much help I can provide, but I've learned a few things about Parent and Child scripts. In my first attempts at loading script object, I was loading from external files, as you are, but now I'm learning to use script objects within the main script. To the script executing, the resulting script object is the same, whether you load from an external file, or call a local script object. (ramble... ramble.... ramble....)

I believe you need to explicitely inherit the parent's handlers and properties using:

property parent : <name of parent script object>

EXAMPLE: (copied from page 334 of the AppleScript Language Guide)

script X
on sayHello()
return "Hello, " & getName()
end sayHello
on getName()
return "Emily"
end getName
end script

script Y
property parent : X
on getName()
return "Andrew"
end getName
end script

tell Y to sayHello()

-- RESULT: "Hello, Andrew"

What happens here is script Y is inheriting script X's handlers, but since script Y already has a getName handler, it uses that one during that execution, resulting in "Hello, Andrew".

Hope this helps a bit.

Ted.


  • Follow-Ups:
    • Re: library of subroutines - help needed
      • From: Ken Victor <email@hidden>
References: 
 >library of subroutines - help needed (From: Ken Victor <email@hidden>)

  • Prev by Date: Re: This worked yesterday: File path question
  • Next by Date: Re: Startup drive in script
  • Previous by thread: library of subroutines - help needed
  • Next by thread: Re: library of subroutines - help needed
  • Index(es):
    • Date
    • Thread