• 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: initializing loaded scripts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initializing loaded scripts


  • Subject: Re: initializing loaded scripts
  • From: Arthur J Knapp <email@hidden>
  • Date: Fri, 03 May 2002 10:55:20 -0400

> Date: Fri, 3 May 2002 11:47:38 +0200
> From: Sascha Kratky <email@hidden>
> Subject: initializing loaded scripts

> I'm using the "load script" scripting command to
> load an external script. Is it possible for the
> loaded script to define an initialization handler
> that is automatically called every time the script
> is loaded or do I have to call an init handler explicitly
> myself?

There is no code in a script that gets run when it is loaded, so yes,
you would have to call an explicit init() handler. However, there are
some tricks about this that you might want to know.

The basic idea is to have your initializing handler return a reference
to itself. This is accomplished simply by returning the keyword "me".

on Init(a, b, c)

[initialize stuff]

return me --> a reference to the loaded script

end Init

This means that a single line of code can both load and initialize the
script:

set myLoadedObject to Init(1, 2, 3) of load script [...]


In truth, there is no real benefit to doing this at runtime,
but this is a very cool way to initialize an object at compile-time:

property InitializedObject : Init(1, 2, 3) of load script [...]



Here is a very simple example, where we want to initialize a compile-time
script object with certain pieces of information:

-- script file "Stuff To Remember"
--
property mainScriptCompileDate : missing value
property mainScriptVersionNumber : missing value
property mainScriptVersionString : missing value

on Init(compileDate, versionNumber, versionString)

set my mainScriptCompileDate to compileDate
set my mainScriptVersionNumber to versionNumber
set my mainScriptVersionString to versionString

return me --> a ref to this script is returned

end



-- script application file "Main Script Project"
--
property StuffToRemember : ,
Init(current date, "1.0.0", "Main") of ,
load script file "MacHD:CompileTimeScripts:Stuff To Remember"



-- another script application file "Another Project"
--
property DoNotForget : ,
Init(current date, "7.5.6", "Another") of ,
load script file "MacHD:CompileTimeScripts:Stuff To Remember"



{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www2.linkedresources.com/tools/carthandle.html>
on error number -128
end try
}
_______________________________________________
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.

  • Follow-Ups:
    • Re: initializing loaded scripts
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Finder Whose by Modification date
  • Next by Date: Property question
  • Previous by thread: Re: initializing loaded scripts
  • Next by thread: Re: initializing loaded scripts
  • Index(es):
    • Date
    • Thread