Re: parent properties
Re: parent properties
- Subject: Re: parent properties
- From: Paul Skinner <email@hidden>
- Date: Mon, 05 Feb 2001 12:42:18 -0500
In the true spirit of "me too!" this is an example of how I use the
Parent Property to give my scripts access to all of my handler libraries and
values.
Please note that the handlers and scripts that I am calling are stored
in ScriptBase so I reference them by drawer and object. It's just a
reference so you can replace it with a call to load a script. I would plunk
down $59.00 for the single user edition of ScriptBase...
http://www.mainevent.com/base.html?cart=9605901
...but that's me.
I have one script saved as stay open application called "propertyserver",
it lives in the scripting additions folder, but it could be anywhere...
---------------------begin script----------------------------
-->>PROPERTYSERVER APPLICATION<<
--this is the PARENT of object "propertylist" in drawer "properties"
--This script acts as a dynamicly modifiable property server.
---------------------------------------------------------
-->>RECENT VALUES<<
property recentVolume : "recent volume"
property recentfolder : "recent folder"
property recentFile : "recent file"
---------------------------------------------------------
-->>PREVIOUS VALUES<<
property previousClipboardContents : "previousClipboardContents"
---------------------------------------------------------
--ect...
--the list of properties in this script continues...
---------------------end script----------------------------
And I have one script called propertylist...
---------------------begin script----------------------------
-->>PROPERTYLIST<<
------------------------------------------------------------------
property parent : application "propertyserver"
-->>This references the "propertyserver" script saved as a stay open
--application in the scripting additions folder.
-----------------------------------------------------------------
-->>HANDLERS<<
property itemIndex : object "itemindex" in drawer "handlers"
property ASVersion : object "asversion" in drawer "handlers"
property asciisort : object "asciisort" in drawer "handlers"
property offsetsof : object "offsetsof" in drawer "handlers"
property stdDate : object "stddate" in drawer "handlers"
property mountvolume : object "mountvolume" in drawer "handlers"
---------------------------------------------------------
--ect...
--the list of properties in this script continues...
---------------------end script----------------------------
There! Now I can add the line ...
property parent : object "propertylist" in drawer "properties"
To the top of any script and use the handlers and values in those libraries.
If I modify a handler that is referenced in the propertylist then I have
to recompile any script that calls it in order for that script to use the
modified handler. Small price.
--Now here's a script that inherits the properties of the
--script "propertylist" and therefore it's parent script "propertyserver".
---------------------begin script----------------------------
property parent : object "propertylist" in drawer "properties"
--TA DA! Now I have access to all of the handlers and values in the
--two scripts above.
--The following property of the propertylist is a handler.
asciisort((every character of "applescript"))
-->{"a", "c", "e", "i", "l", "p", "p", "p", "r", "s", "t"}
--Propertylist values are immutable. ( unless recompiled.)
set asciisort to {2}
-->{2}
--So they can't be damaged.
asciisort((every character of "applescript"))
-->{"a", "c", "e", "i", "l", "p", "p", "p", "r", "s", "t"}
--note that I use the 'my' reference to call properties of the
propertyserver.
--The following property of the propertyserver is a variable.
my recentfolder --Properties in the propertyserver are mutable.
-->"dark star:System Folder:Scripting Additions:"
set my recentfolder to "dark star:System Folder:Preferences:"
-->"dark star:System Folder:Preferences:"
my recentfolder --So they can be modified in a script and any script
--referencing the "recentfolder" property will get the current value.
-->"dark star:System Folder:Preferences:"
---------------------end script----------------------------
Clean handler calls and pretty clean calls to values in the
propertserver. All my stuff in one place. Outside of the need to recompile
scripts, when the handlers they use are changed, I find this works very
well.
This does not address all of the points that have been raised on this
topic, It just shows how libraries of code can be reused fairly simply.
I may have missed something in the other posts on this topic, but it
seemed to me that this was overly complicated. If I have missed the dilema,
I blame the list server! ( scapegoat :)
Now as for writing handlers that are flexible, legible, documented and
good enough to distibute, thats another story isn't it.
Paul Skinner
--
Digital duct tape.