Re: Overloading Additions
Re: Overloading Additions
- Subject: Re: Overloading Additions
- From: has <email@hidden>
- Date: Fri, 6 Sep 2002 14:12:36 +0100
Philip Aker wrote:
>
> Is there any way to overload a scripting addition command? (He asks,
>
> expecting the answer 'no'). The thing that came to mind was that it
>
> would be super-keen to be able to make custom paths for the path to
>
> command. For example, I could have a 'path to "Current Ad PDFs"' in
>
> my script, and it would return the path I want. I know there are
>
> other ways to accomplish this, but it would be nice to use the same
>
> terminology.
>
>
>
> So, is this possible? Is it dumb? Is it both?
>
>
In your script just overload the command:
>
>
on path to (theObject)
>
set x to ""
>
set x to (continue path to theObject) as string
>
set x to x & "somename.txt"
>
return x
>
end path to
>
>
path to (desktop folder)
Yup; btw, this is covered in ASLG, p339, if you want to read it up there.
There's one significant caveat, however: AS handlers don't support optional
parameters, crippling this technique where the app/osax call includes
optional parameters.
For example, overriding 'ASCII character' is fine (one required parameter;
no problem), but 'path to' has an optional 'as [type]' parameter: if you
try to override it you'll either have to include this parameter (making it
a required parameter) or exclude it (removing it from use). Either way, you
defeat the point of overriding the 'path to' call, which is to add extra
functionality (in this case to add extra 'predefined folders') without
breaking existing behaviour. Always add, never take away.
As a result, I'd recommend adding a new function, e.g. pathTo(), instead,
which can wrap the 'path to' command as necessary without interfering with
it. (It's much less elegant/convenient, I know, but until the AS team
figures out how to straighten out the mess that is AS handler syntax and
features, it's just something else we have to live with.)
>
If you need the "real" one, call it like:
>
>
set y to AppleScript's path to theObject
If you need to do this, it's a clear sign that you shouldn't have
overridden the original call in the first place (i.e. see above).
HTH
has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.