Re: Storing script objects (+ visibility of stored properties)
Re: Storing script objects (+ visibility of stored properties)
- Subject: Re: Storing script objects (+ visibility of stored properties)
- From: Sun Real <email@hidden>
- Date: Fri, 19 Jan 2001 13:42:45 +1100
Some days ago, Paul Berkowitz <email@hidden> wrote:
>
It's safer to always include 'alias' when storing script.
But only for existing files, which I realise was the context of your
answer. It's perhaps worth noting though, that this is guaranteed to
break on a new file, or if the old one's been deleted since it was loaded.
'store script' calls for a file spec, so I tend to use something like
this:
store script myScriptObject in file "disk:folder:file" with replacing
Use of the word 'file' means it should work in any context. If one needs
to track the file regardless of name &/or path changes, then by all means
store it as alias within the script, but calling it as alias will still
fail if the script is gone when you come to write back to it. Use of
'file' means that at least you'll write a new one instead of erroring (or
needing to write a trap).
Another thread here recently was about script properties not being
visible when store script is used to replace an existing file. One thing
I noticed when first testing making new files this way was that, at least
under some circumstances, the property contents *are* visible when a new
file is created. I just happened to notice it at the time (I wasn't
looking for it) so I didn't test its limits at all.
The ability to make a new compiled script file with 'store script' is
what makes using them as preference files a practical option for me. If
a user could kill a script by deleting the prefs then they would have
very limited value, but we can easily make a new file containing our
default settings (just like the big kids do), maybe something like this:
script prefScr
property zaPrefs : {"Shut", "Up", "and", "Play", "Your", "Guitar"}
end
set prefPathStr to "disk:folder:file"
try
set currPrefs to load script alias prefPathStr
on error
set currPrefs to prefScr's zaPrefs
end
-- do all your stuff here & then save to a new file:
store script prefScr in file prefPathStr
You can even make a (sort of) new script application using 'store
script', as long as you have a spare shell - just duplicate it, 'store
script' into the copy & you've got yourself a 'new' AS applet, created on
the fly with no 3rd party tools.
Cheers,
Richard Morton
-- Great Lies of the Music Business: "This is one of Jimi's old Strats"