I have been experimenting with OOP and self-initialization in applescript.
Below is a sample of what I believe to be an elegant way to create objects and have them initialize with one line as well as having the object able to initialize itself. However, when my full code is implemented and the script is saved as an application, I can only run the app a few times before a dialog stating "script doesn't understand fobj..." pops up. I suspect a memory issue but I set my obj's to null (thinking I'm managing the memory) so I'm confused as to why this is an issue.
If there are AS/OOPers out there, please take a look and see if you can point me in the right direction.
Thanks!
copy fobj(((path to desktop folder) as string) & "myfile.txt") to obj obj's cp({location:((path to documents folder) as string) & "newname.txt", init:true}) set obj to null
on fobj(str)
script private
property _name : null property _pathalias : null property _creationdate : null property _modificationdate : null
-- and continue defining many, many properties --
on initialize(args) my populateProperties(iteminfo(args)) end initialize
on populateProperties(args) -- pull data from args and populate all properties in script object 'private'. end populateProperties
on iteminfo(args) tell application "Finder" -- pull recordlist of every property of the file object end tell end iteminfo
end script
private's initialize(str)
script public
on _name() return (private's _name) end _name
on _pathalias() return (private's _pathalias) end _pathalias
on _creationdate() return (private's _creationdate) end _creationdate
on cp(args) -- example: cp({location:((path to desktop folder) as string) & "joe.pdf", init:true}) do shell script "cp " & (quoted form of POSIX path of (private's _pathalias)) & space & (quoted form of POSIX path of (location of args)) if (init of args) then private's initialize((location of args)) end cp
end script end fobj
-- Kevin Muldoon, Owner TrueBlueDot - Fine Art Printing New Haven, CT 06511 www.truebluedot.com "Our pigment meets your imagination"
|