A 'character' in InDesign is a base unit of text *including* its formatting, and so it's a composite object. You cannot compare it to a literal character value such as 'return'. To access the *literal* characters, you can use 'contents':
(Translate into AS as you see fit )
This does a number of things in one line:
1. app.selection is your selected text
2. its "contents" is a regular string of Unicode characters
3. the match command does a regular expression, that
3a. matches anything not 'return' or 'linefeed' from the start of the string
3b. 'match' returns an *array* of found substrings, which may be 'null' (i.e. it didn't match anything)
3c. ... however, I *think* that using this regex will always return a single string result -- numbered '0' in JS
4. .... and the length of this string is the number of regular characters from the start of your selected text.
Actally i cant really translate this to AS because im not so skilled with it, but thank you for your help.
I somewhere found some AS-stuff using "contents" and didnt know what to make of it, but ill look deeper into that, this should help.
Some pros and cons -- other readers are invited to chime in here!
- you can use it in any supported application in OS X
- you can use one single script to target different applications (f.i., copying text from one app to another)
- it's only for OS X
- personally, I *hate* the 'human readable' syntax. For simple one line commands it works, but with anything involving more than a single "x of y in z" I get lost in my train of thoughts
- you can use it in any supported application (granted, there aren't too many ... Adobe's software, in general, but also in all Web browsers!)
- it's platform independent. The same script runs on both Windows and OS X.
- it has a logical syntax -- my app.selection example above can be read left to right, and all objects and commands right of a period are immediately applicable to the object to its left
- the syntax is logical, but only if you are a trained programmer It's not as intuitively as AppleScript
I see the Pro's for JS, but i have no choice here: As a designer I dont get much time windows to work on scripting. So if i have a project done, i can code some stuff. As im not a trained programmer i find it hard to get into a unknown syntax at all. Somehow i discovered AS and changed this and that in sample scrippts and got a bit better, just enough to enhance my workflow as a designer.
It is very kind of you to show me the Cons of AS, but i'm stuck with it right now and cant let you guys code my whole scripts in JS, nor i cant change them after that :-)
But thanks anyway.
While we're at it, i got stuck with my script, regarding of programming language. Can you help me out or should I open a new thread?
I have a textselection in a textbox. And I need to know the x-choordinate to the right of the selection, but only in the first line of the selection (if it spans over two or gets broken into another paragraph.) I managed it by counting the characters till a shift in baseline of the char happens. But with superscripted characters or rotated textboxes this isnt the optimal way. So, i asked the question above to figure out of my textseletion contains a breaking character, but this wont work if the text just flows into the next line. Do you have any idea with wich character property to work to get this right? I'll provide a picture here:
I only want to get the xchoordinate of the selections first line, no matter what break follows. (To provide the user accidentally selection "over" the lines end).
also JS but if we talk about the rules:
this your X coordinate of right of first line of selection