• 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
access to reparented enclosing script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

access to reparented enclosing script


  • Subject: access to reparented enclosing script
  • From: Mitchell L Model <email@hidden>
  • Date: Wed, 29 Jun 2016 13:43:57 -0400

Here we go again. Some of my recent experiments were spawned by the following situation, which I badly need to resolve (though for present purposes I have an ugly workaround). I am working on adding ONE DAMN FEATURE to someone else’s sophisticated pair of object-oriented scripts that work just fine. The Support script is intended to be used by many Other scripts. Let’s say it is in ~/Library/Script Libraries (even though, as per one of my recent posts, aI really want it in the same folder as the Other scripts.) I am writing one such Other script; let’s call it Mine. Scripts that use Support create subclasses of Support scripts by reparenting  So, ignoring some of the complexity, here is the bare bounds structure of Mine that is relevant to my ONE DAMN FEATURE.

[I believe that the issues that have come out of my efforts are interesting in themselves, but more importantly worth discussing because I will be distributing the scripts (with or without the ONE DAMN FEATURE), and I believe they will be of considerable interest and use to the AppleScript community. The real work has been done by other people — I am just trying to add this ONE DAMN FEATURE, some further documentation, and a skeletal example of using Support.]

-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
use AppleScript
use scripting additions
property parent : script "

----------------------------------------------------------------
script Outer1
    parent: makeOuterParent(me)

            -- At the time the value of parent is compiled, Outer’s parent is the top-level script,
            -- whose parent is Support, which contains a top-level handler makeOuterParent.
            -- makeOuterParent returns a script object (which are actually closures).
            -- After parent is set to the newly obtained script object it can no longer access
            -- any of the identifiers from its lexically enclosing (implicit) script object  
            --
            -- I still don’t understand how the value of me is Outer during compilation, but ...

--------------------------------
    script Inner1
        parent: makeInnerParent(me)
            --- commentary as above
           -- -- do something ----
    end Inner1

--------------------------------
    script Inner2
        parent: makeInnerParent(me)
            --- commentary as above
           -- -- do something ----
    end Inner2

    ---- more Inner Scripts ----

end Outer 1

----------------------------------------------------------------
script Outer 2
    ---- Inner scripts ----
end Outer2

-------- more Outer scripts --------

runThem()
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

makeOuterParent and makeInnerParent “register” the scripts that call them in a list
in the process of constructing parents for the Inner and Outer scripts.

The handler runThem is run when this script is run.


runThem runs each of the Inner scripts of each of the Outer scripts that have registered themselves.
BUT IT DOES NOT RUN THE OUTER SCRIPTS.

Everything works fine, despite some further intense voodoo and heavy parenting inside of Support.

Now, the ONE DAMN FEATURE I want to add is to be able set a variable at the top level of Mine that is accessible inside of the Inner scripts. (If you are trying to think this through, remember that the parents of the top-level script, the Outer scripts, and the Inner scripts are all script objects in Support. Those script objects do have parents, but not each other, so there is no way to work through the parent hierarchy from an Inner handler to the top-level script's context.

Despite a great deal of wiggling, squirming, time spending, and appealing for help on pieces of this problem, I still do not have a solution. At this point I am convinced that there is none.

But wait! As often happens when trying to carefully and completely describe a problem, new solutions present themselves. I have another idea to try, but I'm going to leave this post for discussion while I go off and try it.

Thank you for listening. I hope you can follow my description -- and believe me, the reality is more complex than the abstraction presented above — and enjoy the challenge.







 and what I need for my ONE DAMN FEATURE.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: path to script file in script's folder
  • Next by Date: Re: path to script file in script's folder
  • Previous by thread: Re: AppleScript-Users Digest, Vol 13, Issue 279
  • Next by thread: Re: access to reparented enclosing script
  • Index(es):
    • Date
    • Thread