Re: hash arrays and other mysteries
Re: hash arrays and other mysteries
- Subject: Re: hash arrays and other mysteries
- From: has <email@hidden>
- Date: Sat, 20 Oct 2001 15:02:55 +0100
Paul Skinner wrote:
>
> One of the things I'm trying to do is make a script server that can
>
> dynamically load an arbitrary collection of handlers blah-blah-blah
>
>Unfortunately, one of the problems of the modular modular
>
> approach is that you can soon find yourself writing lots of lines like:
>
>
>
> tell application "scriptserver" to foo() of bar
>
>
>
> when all you really want to write is:
>
>
>
> property parent : application "script server"
>
>
>
> which you've only got to do once, and then, whenever you want foo(), all
>
> you gotta use is:
>
>
>
> foo()
>
>
>
>
Right. So there's your answer. Apparently you don't want this solution? Or
>
are you saying that you are having no luck implementing this? I do just that
>
and it works like buttah.
True, and it's really simple when the handlers are in the script server
too. But having them in libraries which are then loaded by the server is a
bit trickier/messier, as I found out from Bill Cheeseman's site:
http://www.AppleScriptSourcebook.com/tips/scriptserver.html. (And having to
wrap the contents of every lib in an explicit "script foobar" statement
goes against the 'maximum simplicity' I'm after - though I do think it's a
very clever trick.)
>
--begin script
>
property parent : application "AppleScriptServer"
>
display dialog "Enter your name." default answer "Paul Skinner"
>
writedata({theData:swapCase(asciisort(every character of the text returned
>
of the result) as text)})
>
--end script
Exactly what I'd like to do.
If I lose it completely, I could probably figure a way to use URL Access
Scripting connect to the Applemods site and download any missing mods that
your script might try to call. Hmmm... might want to leave that till the
v2.0 though... ;)
>
Why do you want to modify the handler server dynamically? What is it
>
that you're trying to do?
Good question: I might just about have grasped OO programming, but I've yet
to develop the skills to describe what I'm trying to achieve with it.:)
OK, here's the idea: you have a folder called "AppleMods" or "Script
Libraries", or whatever the name would be (in Classic that might reside in
the Scripts folder; I dunno about X). Into that you can toss any number of
modules as and when you like. The scriptserver will read the contents of
any new modules (either using an idle handler to do periodic checks, or
perhaps by triggering it from a folder action) and add their handlers to
itself, such that they'll be directly available from the scriptserver
itself:
tell app "scriptserver" to foo()
or:
prop parent : app "scriptserver"
foo()
I'm still not 100% sure this is possible, but I reckon it's worth a try.
(Hmmm... for extra points, maybe the script server could even be made into
an FBA? Beyond me though.)
>
> And then I go and look at Python, with directories and sorts and regex and
>
> import and so many other juicy apples all as standard, and I can feel a
>
> moment of weakness coming on. But I shall continue to be strong and resist
>
> that wicked old snake, though it may tempt me at times like these... ;)
>
>
Don't give in! I have found the Perl mods to be my greatest temptation.
I can visualise Perl driving around in a big black van... suddenly it pulls
up beside you, rolls down the window, then cracks its dirty pockmarked face
into a yellowed toothy grin and purrs softly:
"Would you like to see some Perl mods, little boy?"
Aaaaaah! Scareeey. Though not as scary are seeing obfuscated Perl for the
first time. Now that was REALLY frightening. :O
(BTW, if the above ever finds its way to a Perl Advocacy group I'm a dead
man, so please don't tell them I said that!:)
>
Applemods does have a great concept in creating a space for this type of
>
effort. I think that the freeform nature of most scripter's coding and lack
>
of any call-return standard is going to limit it's usefulness though.
tell app "scriptserver" to getModInfo([modname])
-->{title:"findAndReplace",
author:"John Smith",
version:1.01,
description:"A TID-based find-and-replace handler.",
input:"findAndReplace([the text to search], [a string, or list of
strings, to search for], [safesearch - boolean])",
output:"[the processed text]"}
Or it could just as easily come back as a nicely-formatted, easy-to-read
string. Whatever.
Folks ought to be documenting their stuff at at least that sort of level
anyway, certainly if they're releasing it for public consumption, so
putting the info into nice machine-readable properties shouldn't be a big
step up from writing it in comments. Some folks already do, at least for
some info - it all just needs standardised as to what needs to be included
and what the property names should be. Then insist on it in the submission
rules. Or maybe even use a nice packaging tool like ScriptBuilder SP (which
packages complete scripts for upload to macscripter).
>
Now if there was a way to get everyone to agree on 'standard' input and
>
output for handlers, we might even get the idea of mods for AppleScript off
>
the ground.
>
>
BAHAHahahah! Well, I TRIED to say 'standard' with a straight face. We all
>
know that it isn't likely that everyone will use any standard even if some
>
people could agree on what that should be.
Heh. And I tried to read it with a straight face... and also failed. "You
can lead a horse to water, but you can't make it drink." (I think we're
more like mules, myself: you'd be lucky getting any of us even NEAR the
water.:)
Still, if other languages can do it, there must be a way to make it work.
Cheers,
has