Re: How do I delete the 1st three characters from a variable
Re: How do I delete the 1st three characters from a variable
- Subject: Re: How do I delete the 1st three characters from a variable
- From: has <email@hidden>
- Date: Fri, 6 Jan 2006 14:25:46 +0000
Shane Stanley wrote:
> > I take it back, you merely misunderstood.
>
>In that case I'm probably going to do it again.
No problem, it's what we're here for. ;)
> > text from character x to character y
> >
> > is just a synonym for:
> >
> > text (character x) thru (character y)
> >
> > which is a shortcut for:
> >
> > text x thru y
>
>OK, so you're saying the first two are shortcuts for the last.
Oops, other way about. The first two are the same, and the last is a shortcut for that. That's what happens when I write posts after midnight; they all turn into pumpkins. :p
Also, I wasn't watching my wording that time: what I should've said was that 'text x thru y' really expands to 'text (text x) thru (text y)', but the application should interpret this as 'text (character x) thru (character y)'. More on this below.
> > The first two mean the exact same thing, so it makes not one jot of difference
> > which way you write it. The last doesn't, but is usually expanded to the other
> > form under the hood for the user's convenience
>
>So you're saying the long form is "expanded" under the hood into the
>shortcut.
The short form is "expanded" under the hood into the long form.
OK, just so you know, a by-range specifier consists three parts:
1. the class of the elements being specified
2. a reference to the first element in the range
3. a reference to the last element in the range
Most of the time users aren't aware that this is their true structure, because AS allows scripters to write by-range specifiers without expressing those start and end references in full. They can just supply a couple of index numbers and AppleScript automatically expands these into references for them based on the available information. e.g. When AppleScript sees the reference:
words 5 thru 9 of document 1
it effectively expands it to:
words (word 5 of container) thru (word 9 of container) of document 1
before packing it into an Apple event and sending it off to the application. (If you turn on the AEDebug options and watch the events that AS sends to applications, you'll see this.) The application then figures out which objects all these references mean and does its funky stuff. In the above case, the container for the sub-references is document 1, so it finds word 5 of document 1 and word 9 of document 1, and then finds all the word objects inbetween those two points as well.
If all that is a bit hard to follow, it is; which is why allowing the user to write the shortened form, 'words 5 thru 9', is so damn helpful. In most cases, AppleScript takes care of everything, but in a few corner cases - e.g. 'text 3 thru 6' - the application needs to help out a little bit too.
The trouble with using a reference like 'text 3 thru 6 of document 1' with [e.g.] Tex-Edit Plus is that TE+ misinterprets the 'text 3 of container' and 'text 6 of container' references that AS generates. It ought to evaluate 'text 3 of container' the same way as it evaluates 'character 3 of container', but the application's designer didn't realise this and so didn't implement the code to do it. The user isn't aware of this because application documentation hardly ever goes into this level of detail, so they just write some code that looks like it should work and hope for the best; and if it fails then they just keep on experimenting till it does. And they'll probably never truly understand why it originally failed, because they aren't really aware of all the magic going on under the hood. Which is always the problem with magic: it's great until something goes wrong with it, and then you're in the soup.
Anyway, you can't really blame the developer, as it's really hard to be sure you've thought of every last corner-case, especially when dealing with such a loose and ill-documented specification as the Apple Event Object Model's is. And you can't blame the user, because they're just doing their best with what little information is provided. All you can really do is send the developer a polite enhancement request in the hope that they'll iron out this wrinkle in future releases (feel free to include the above if it'll help).
Again, apologies for any confusion my previous botched attempt at late night erudition may have caused, and hope the above finally makes sense of everything.
Cheers,
has
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden