Re: Storing preferences?
Re: Storing preferences?
- Subject: Re: Storing preferences?
- From: Kai <email@hidden>
- Date: Fri, 07 Feb 2003 00:24:17 +0000
on Wed, 5 Feb 2003 15:31:10 -0500, James Burns <email@hidden>
wrote:
>
Here's what I'm trying to do -- Write a preference file.
>
>
My questions?
>
>
1/ What's the best way to implement this? I looked at the sample
>
application in the examples/applescript studio folder of the December
>
2002 developer's release, but can't quite wrap my head around what's
>
involved. Is there a simple scheme for doing this just with Applescript
>
i/o commands, and not calling obscure Cocoa routines?
>
>
2/ In that vein, is there a way to overwrite files automatically
>
(without user intervention) if they exist? That way I could write a
>
simple text file with the info I want to retain between sessions
>
without bugging the user at quitting time.
I see you've already had a couple of suggestions, James. To extend your
options a little further, I've outlined a vanilla routine below. Much of the
content is included to demonstrate how the script works - so it's not as
complex as it may initially appear.
>
3/ Any suggestions for the structure of the preference file? Text?
>
Records? Delineated how?
This could depend on the type of data you're trying to store but, for
relatively simple values, I'd probably go for a record or a list. The
following example uses a record:
==========================
property p : missing value
to setDefaultPrefs()
set p to ((path to preferences [NO BREAK]
from user domain) as string) & "myPrefs" -- amend as required
set o to open for access p with write permission
write {x:"one", y:"two", z:"three"} to o -- amend as required
close access o
end setDefaultPrefs
to getPrefs()
read p as record
end getPrefs
to savePrefs(r)
set o to open for access p with write permission
set eof o to 0
write r to o
close access o
end savePrefs
to showPrefs(r) -- demo only
display dialog "x = " & r's x & [NO BREAK]
", y = " & r's y & ", z = " & r's z
end showPrefs
to changePrefs(r) -- demo only
set r's x to (display dialog [NO BREAK]
"Change x to:" default answer r's x)'s text returned
set r's y to (display dialog [NO BREAK]
"Change y to:" default answer r's y)'s text returned
set r's z to (display dialog [NO BREAK]
"Change z to:" default answer r's z)'s text returned
r
end changePrefs
if p is missing value then setDefaultPrefs()
set r to getPrefs()
showPrefs(r) -- demo only
set r to changePrefs(r) -- demo only
savePrefs(r)
==========================
--
Kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.