• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating preferences for an applescript application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Creating preferences for an applescript application (From: Paul Berkowitz <email@hidden>)
 >Re: Creating preferences for an applescript application (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Unicode-to-string bug?
  • Next by Date: Re: Anyone scripting PowerPoint 2004?
  • Previous by thread: Re: Creating preferences for an applescript application
  • Next by thread: Re: Creating preferences for an applescript application
  • Index(es):
    • Date
    • Thread