[I am reposting because all my indentation disappeared in the last post, and it will be almost impossible to follow this without the indentation. My apologies.]
In the last installment of this puzzle, I asked naively why with this code:
property pathToMe1 : (POSIX path of (path to me as text)) property pathToMe2 : missing value set pathToMe2 to (POSIX path of (path to me as text)) {pathToMe1, pathToMe2}
pathToMe1 is the path to Script Editor or Script Debugger pathToMe2 i the path to the script, which is what I want
[Here is another in my series of explorations into the semantics and mechanisms of AppleScript. I apologize if the length of this one is not worth the mystery it presents, or if the mystery has an obvious explanation I should have seen. The mysteries are presented on lines beginning ***.]
pathToMe1 was the path to SD (or SE or whatever) but pathToMe1 was the path to the script. Shane Stanley explained that property values are compiled before the script exists. But now let’s take this a little further:
property pathToMe1 : path to me -- (a) property pathToMe2 : missing value -- (b) property theScript : me -- (c) property theValue : 1 -- (d) set pathToMe2 to path to me -- (e) set pathToMe3 to path to theScript -- (f) on setTheValue() set theScript's theValue to 2 -- (g) log theValue -- (h) = 1 log theScript's theValue -- (i) = 2 end setTheValue setTheValue()
theScript contains itself, recursively. Almost all of this makes sense, after taking into account Shane’s comment about what "me" means at compile time.
when the script is compiled (a) pathToMe1 is the path to the compiler (b) pathToMe2 is initialized to missing value (c) theScript is initialized as itself (d) property theValue initialized to 1
when the script is executed: (e) pathToMe2 is set to the path to the script (f) pathToMe3 is set to the path to theScript, whose value is the script (g) theScript’s value is set to 2 *** (h) theValue is 1 (i) theScript’s theValue is 2 after the script is executed, just as during execution: *** “theValue" is 1 "theScript’s value" is 2 "theScript is me" is true
*** What I can’t explain is how “theValue” is 1 but “theScript’s theValue” is 2, even though “theScript" equals “me”, and the script’s properties should be able to be modified inside the handler.
*** A further mystery: running this script with osascript, pathToMe1 is the path to osascript, BUT, “theValue” is 2 not 1. |