Re: persistence of script properties
Re: persistence of script properties
- Subject: Re: persistence of script properties
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 05 Mar 2005 07:18:44 -0800
Title: Re: persistence of script properties
On 3/4/05 11:18 PM, "Donald Hall" <email@hidden> wrote:
I thought that script properties that were changed when a compiled script was run were saved by the 'store script' command, but this does not seem to be the case. My reading of Goodman and Neuburg both lead me to believe that when I load a script, run it in a way that changes its properties, then store it, then reload it and run it again, the changed values of the properties should be there. Here is my example:
-- script runner
property theScriptAlias : ""
if theScriptAlias = "" then
set theScriptAlias to choose file of type {"osas"} -- choose file containing my test script below
end if
set theScript to load script theScriptAlias
run script theScript
display dialog "after run: theScript's x is " & theScript's x
store script theScript in theScriptAlias replacing yes
-- end of script runner
-- test script
property x : 0
set x to x + 1
activate me
display dialog "x is " & x
-- end of test script
I set theScriptAlias to be the file containing my test script.
The test script runs, displaying "x is 1".
Then I get "after run: theScript's x is 0", not '1' as I would expect.
Of course, when I rerun my script runner, I still get "x is 1", not "x is 2", which I would have gotten if 'x' had been saved by 'store script'.
Can anyone explain this?
Change the line
run script theScript
to
tell theScript to run
and you'll see what you were expecting; "after run: theScript's x is 1", and then "2" on the next run, and so on.
You were using the osax 'run script'. 'run script' seems to run a separate instance of theScript in memory. It doesn't seem to affect the properties of the variable theScript representing the loaded test script, so when you store theScript you're just storing the same script object with the same values you started with. If you tell the loaded script to run, on the other hand, then its own property x's value is changed and later stored with the new value.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden