• 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: Paul Berkowitz <email@hidden>
  • Date: Fri, 03 May 2002 08:42:54 -0700

My head's going around in circles here, Arthur. What does this accomplish,
in the end? Which script has its properties set? The loaded script "Stuff to
remember"? Or the main script? What would be the advantage of doing this
within the property declaration of the main script?

--
Paul Berkowitz


On 5/3/02 7:55 AM, "Arthur J Knapp" <email@hidden> wrote:

>> 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"
_______________________________________________
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: email@hidden (Michael Sullivan)
References: 
 >Re: initializing loaded scripts (From: Arthur J Knapp <email@hidden>)

  • Prev by Date: Re: offset with spaces confusion
  • Next by Date: EXCEL SCRIPTING
  • Previous by thread: Re: initializing loaded scripts
  • Next by thread: Re: initializing loaded scripts
  • Index(es):
    • Date
    • Thread