Re: Storing preferences, part deux
Re: Storing preferences, part deux
- Subject: Re: Storing preferences, part deux
- From: Paul Skinner <email@hidden>
- Date: Thu, 6 Feb 2003 13:40:37 -0500
On Thursday, February 6, 2003, at 12:47 PM, James Burns wrote:
On Wednesday, February 5, 2003, at 07:03 PM, Philip Aker wrote:
On Wednesday, February 5, 2003, at 12:31 PM, James Burns 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.
3/ Any suggestions for the structure of the preference file? Text?
Records? Delineated how?
The shell command 'defaults' can do amazing things if your
requirements for a preferences file are modest.
In Terminal or in a 'do shell script' this will create your prefs
file if it doesn't exist and put in the first entry:
defaults write com.burns.FirstApp SomePref "99"
This will retrieve it:
defaults read com.burns.FirstApp SomePref
This technique is even good for itty-bitty AppleScripts.
Cheers,
Philip Aker
http://www.aker.ca
This is a great idea, but I've run into another problem. Saving works
like a charm, but I'm ambitious. I want to save an array, because in
the future I might have a list of settings and might want to save
multiple lists (make sense?).
No problem I think, the command "defaults" lets you save an array,
using the command:
defaults write somedomain preferenceKey -array element1 element2
element3
So, I write the Applescript, and get it to work. I check the plist
file and, sure enough, I have an array of text strings under the name
I gave to the preferencekey (let's call it "test"). Life is good.
Here's where the problem comes in... If I try to get those values back
in the terminal by using the command:
defaults read myApp test
I get back:
(
"Macintosh HD:Applications:LightWave 3D 7.5:configs:",
"Macintosh HD:Applications:LightWave 3D 7.5:Programs:",
"merely big:JPB Projects:News24 Houston:",
"huge:renderspace:News24_Open_02.",
1,
80,
1
)
Not an array (or "list" in AppleScript talk...), but what appears to
be a weird string with parenthesis instead of braces,
returns at the end of the lines, and generally a mess.
If I do a "log result" I get:
"(
\\\\"Macintosh HD:Applications:LightWave 3D 7.5:configs:\\\\",
\\\\"Macintosh HD:Applications:LightWave 3D 7.5:Programs:\\\\",
\\\\"merely big:JPB Projects:News24 Houston:\\\\",
\\\\"huge:renderspace:News24_Open_02.\\\\",
1,
80,
1
)"
My question, now? Is there a way to parse this mess to get a
reasonable result back? It seems funny that you can save as an array,
but what comes back is a buncha strings.
Thanks, again.
-----
James Burns
http://www.jamesburnsdesign.com
Try playing with the read-type.
from the man page: defaults [currentHost | -host hostname]
read-type domain key
using array as your type.
--
Paul Skinner
_______________________________________________
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.