Re: Script Objects
Re: Script Objects
- Subject: Re: Script Objects
- From: Jon Pugh <email@hidden>
- Date: Mon, 18 Jan 2010 15:29:06 -0800
At 4:31 PM -0600 1/18/10, Luther Fuller wrote:
>What can I do with script objects that I absolutely could not do without them?
>(Or, should I continue to ignore them?)
Technically, you use a script object every time you write a script. The file is the object, properties are the data and the handlers are the methods.
That said, you can probably continue to ignore them.
However, writing complex programs using objects is a common practice. The trick is that complex AppleScripts are not something everyone writes. Most of mine are pretty simple, although I use script objects regularly in the form of my SmartString object:
http://www.seanet.com/~jonpugh/software/SmartString.applescript
(Use MacRoman encoding for that page to get all the special characters.)
The largest issue is that there's no simple way to handle multiple script objects in vanilla AppleScript. We've discussed "load script" techniques before, and the MacMods has their own methods, and Script Debugger has its technique which I use, so there's lots of different ways to manage script objects. Everyone needs to find one that works for them.
I originally came up with this scheme back in the finderLib days. It compiles a copy of the script object/library into the main script, along with an alias to the file, so that if it gets updated, then this script will automatically reload it when run or recompiled.
It's uses SmartString as an example library:
-- the alias follows the file if it's moved or renamed
property ssFile : alias "SuperDisk:Users:jonpugh:Library:Application Support:Script Debugger 4.5:Script Libraries:SmartString.scpt"
-- the modification date is burned in at compile time
property ssDate : modification date of (info for ssFile)
-- as is a copy of the loaded script object
property SmartString : load script ssFile
-- at run time
try
-- we check the mod date
set modDate to modification date of (info for ssFile)
-- if newer
if modDate > ssDate then
-- load the newer one into our property,
-- where the original was stored at compile time
set SmartString to load script ssFile
-- remember the date for the newly loaded file
set ssDate to modDate
--display dialog "I'm loaded"
end if
on error m number n
--display dialog m & return & n
end try
tell SmartString's SmartString
setString("welcome to the machine")
betweenStrings("wel", " to the")
end tell
So, the original question was, what can you do with script objects, and that's simply to break a long complex script into multiple pieces, each with separate areas of responsibility and functionality, primarily for logical separation and future reuse.
I primarily go for reuse, as demonstrated in my examples.
Jon
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden