Re: Storing preferences?
Re: Storing preferences?
- Subject: Re: Storing preferences?
- From: Andrew Oliver <email@hidden>
- Date: Wed, 05 Feb 2003 16:41:37 -0800
My preference (no pun intended) for preference files is to use another
script. You can then use 'load script' and 'save script' to load and save
the preferences respectively.
Something like:
----- begin script -----
script defaultPreferences
-- This is used if there's no existing preference file
property pref1 : 1
property pref2 : 2
property pref3 : "some string"
-- etc. any AppleScript property can be saved here, including lists.
end script
-- use a global so they can be referenced anywhere in your script
global userPrefs
on loadPrefs()
try
set userPrefs to load script "path:to:preferences:file"
on error
-- oops, preferences file doesn't exist, so use defaults
set userPrefs to defaultPreferences
end try
end loadPrefs
on run
-- load the preferences
loadPrefs()
--rest of script goes here
-- copy a preference value into a local variable
set mylocalPref to pref3 of userPrefs
--or set a preference value
set pref3 of userPrefs to "some new string"
end run
on quit {}
--when you're done, save the prefs
store script userPrefs in file "path:to:preferences:file" replacing yes
end quit
----- end script -----
With a little extra work you can include versioning in the preference file
so that you know what values are stored there, adding new ones as your
script develops.
Andrew
:)
On 2/5/03 12:31 PM, "James Burns" <email@hidden> wrote:
>
Hello:
>
>
First of all, a quick thanks to everyone who has helped me in the past
>
couple of days with my newbie questions. This list has been invaluable
>
in my learning process.
>
>
Now that I've buttered you all up, I've got a few more questions. I
>
have the feeling that these are common questions, but I'm only
>
resorting to bugging y'all after fruitlessly searching for answers on
>
the World-Wide Web.
>
>
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.
>
>
3/ Any suggestions for the structure of the preference file? Text?
>
Records? Delineated how?
>
>
Thanks for your suggestions.
>
>
-----
>
James Burns
>
http://www.jamesburnsdesign.com
>
_______________________________________________
>
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.
_______________________________________________
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.