Re: Persistance of Properties
Re: Persistance of Properties
- Subject: Re: Persistance of Properties
- From: "Jason W. Bruce" <email@hidden>
- Date: Tue, 16 Oct 2001 11:31:52 +0000
Irwin,
You create a separate script file "myProperties" using Script Editor and
define a property in it called foo:
Property foo : {1, 2, 3}
Then, at the top of your main script, you import myProperties using load
script:
set bar to load script alias "Hard drive:myProperties"
choose from list (foo of bar) -- will display 1, 2, and 3
set end of foo of bar to 4
store script foo of bar in alias "Hard Drive:myProperties"
with replacing
If you edit your main script and recompile, choose from list will now
display 1, 2, 3 and 4.
Your script below isn't working because you are using the Finder to make a
new file as opposed to Script Editor. Remember, also, that store script is
a scripting addition, and therefore requires a strict path name as its
parameter -- alias "Hard drive:desktop folder:foo" -- as opposed to file
"foo" of desktop -- which is Finder syntax.
The load script technique is also useful when you need to avoid recompiling
scripts which use raw syntax -- as with, for example, custom fields in the
Palm Desktop. You can define a separate script file which contains handlers
defined using raw syntax. You can then load these scripts into your main
script and use their handlers without worrying about losing the raw syntax
upon a recompile in your main script.
Jason Bruce
>
Jason,
>
>
Thanks for the suggestion - sounds like what I need. I've been trying to
>
get it to work but to no avail. This script gets an "Can't make some data
>
into the expected type" on the "store script" line...
>
>
tell application "Finder"
>
set myproperties to {1, 2, 3, 4}
>
if not (file "foo" of desktop exists) then make new file at desktop with
>
properties {name:"foo"}
>
store script myproperties in file "foo" of desktop with replacing
>
end tell
>
>
Doing a bit more research and experimenting I arrive at the following.
>
While it doesn't fail, it doesn't work either. Both the data and resource
>
forks of foo are completely empty.
>
>
script persistableStuff
>
property myproperties : {7, 8, 9}
>
end script
>
tell application "Finder"
>
set myproperties to {1, 2, 3, 4, 5, 6, 7}
>
if not (file "foo" of desktop exists) then make new file at desktop with
>
properties {name:"foo"}
>
tell me to store script persistableStuff in file "foo" of desktop with
>
replacing
>
end tell
>
>
Any idea how to get this sort of thing to work ?
>
>
-Irwin
>
>
>
>
From: "Jason W. Bruce" <email@hidden>
>
Date: Mon, 15 Oct 2001 17:09:04 +0000
>
To: <email@hidden>
>
Subject: Re: Persistance of Propertie
>
>
>
Irwin,
>
>
Load script and store script are tailor made for maintaining properties
>
through recompiles.
>
>
set myproperties to load script alias "Hard drive:foo"
>
>
your script here
>
>
store script myproperties in alias "Hard drive:foo" with replacing
>
>
Jason Bruce