Re: Creating preferences for an applescript application
Re: Creating preferences for an applescript application
- Subject: Re: Creating preferences for an applescript application
- From: Dan Belfiori <email@hidden>
- Date: Tue, 23 Nov 2004 22:31:03 -0800
I write and read the preference data as a record and store the
preference record in a file in the users preferences folder (In the
following example "MyApp Prefs"). The property "Default Record" holds
the initial preference values. You can add more properties to the
Default Record at any time.
property DefaultRecord : {name:"Joe", Age:"33", Hobbies:{"applescript",
"bowling", "sailing"}}
set MyRecord to GetPrefs("MyApp")
set AHobby to item 2 of (Hobbies of MyRecord)
set TheDialog to display dialog "item 2 of Hobbies is :" default answer
AHobby
set item 2 of (Hobbies of MyRecord) to text returned of TheDialog
SetPrefs("MyApp", MyRecord)
on GetPrefs(MyApplicationName)
set Pfolder to path to library folder from user domain
set PrefFile to (Pfolder as text) & "Preferences:" & MyApplicationName
& " Prefs"
try
close access file PrefFile
end try
try
set PrefFile to PrefFile as alias
set Drecord to read PrefFile as record
set Drecord to Drecord & DefaultRecord
return Drecord
on error
open for access file PrefFile with write permission
write DefaultRecord to file PrefFile
close access file PrefFile
set PrefFile to PrefFile as alias
return DefaultRecord
end try
end GetPrefs
on SetPrefs(MyApplicationName, Drecord)
set Pfolder to path to library folder from user domain
set PrefFile to (Pfolder as text) & "Preferences:" & MyApplicationName
& " Prefs"
try
close access file PrefFile
end try
open for access file PrefFile with write permission
set eof file PrefFile to 0
write Drecord to file PrefFile
close access file PrefFile
end SetPrefs
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden