Script: PrefUtility

Author: Luke Wigley
version: 1.0.2
modified: Tuesday, 9th November 2004, 11:49 am


This script allows several objects to read and write their prefs (property/value pairs) to a single pref file. To save prefs, an object needs to call the SaveObjectPrefs method, specifying an id and a property list of property/value pairs to save. For example, if you had a script called 'FileBrowser' and you want to save the last Directory the user selected, you could do this:

   Prefs = script("PrefUtility")

   Prefs.SaveObjectPrefs("FileBrowser", [#LastPath: myLastPath])

To get prefs, an object calls the GetObjectPrefs() method, passing the id and a reference to itself. The values are set directly into the object. For example, the 'FileBrowser' script could read (and set) its prefs like this:

   Prefs = script("PrefUtility")

   Prefs.GetObjectPrefs("FileBrowser", me)

Note. You need to call the "WritePrefsFile" method to actually save the prefs to disk. For example:

  on stopMovie




v.1.02 Added fix where saving a symbol would be restored as a string (by manually inserting the "#" character before the symbol name.

v.1.01 Changed the way the script tests whether it can evaluate a string into a different type It tests (1) whether the string starts with a quote (always treats this as a string; and (2) whether the string version of an evaluation is the same as the original string.

v.1.00 First version.

Public Interface

Methods Description

GetObjectPrefs (me, id, obj)

Applies values extracted from the pref file to the specified object.

SaveObjectPrefs (me, id, inList)

Stores the values in the specified list. The property names should match the property name in the object saving the prefs

WritePrefsFile (me)

Call this method on stopMovie (etc) to actually write the the prefs to disk

new (me)

Note - this is a 'single instance' script (the script object is returned if you try to make a new instance)

PrefsExist (me, id)

A Method for checking whether of not some prefs exist for the specified ID.

Init (me, PrefFile)

Manually load the prefs from disk and initialise the object. (If you do not do this, this script will automatically load the prefs from disk the first time you call any of its methods)