First post here!
Anywhoo, I’m trying to select text relative to a string to be searched for, so after I find the string in the document, I can then select the n number of characters that are l lines down and s spaces to the right. That kind of thing. I’ve “accomplished” this using UI scripting in TextEdit, but the delays and failure rate are killing me, plus it takes forever if you have a lot of things to find, and you can’t background it while the scripts running. Here’s an email I’ve sent to Tom, the maker of Tex-Edit Plus. No response yet, so in the meantime I thought I’d share with you…
In a file full of potentially thousands of segments that look like the following example, I need to copy the bold bits to four variable lists (rank/signature, 1st eigan, 2nd eigan, third eigan).
I’ve accomplished this using ui scripting with TextEdit (the eigan values are always 7 lines down from the CP #, and start five places to the right, etc…), but that can take a long time depending on the number of data you are taking, and also has a high failure rate depending on the speed and number of background processes of the computer running the script (which I corrected for by having the script do checked of the last copied data and restart with a higher delay in between System Events commands).
I want to use Tex-Edit to do this because using built-in scriptability should eliminate the need for checking the data before moving to the next data, and also allow the script to run while Tex-Edit is in the background, allowing me to do other things while the data is being fetched.
So far, the (tiny) script I’ve written for Tex-Edit will open the file, convert it from unix to mac, and search for the first CP to find. After that, I can’t seem to figure out how to change the selection to where I want. From there, I’m not exactly sure how to set the n’th value of a list to the selection.
Lastly, on the chance I want all of the CP information, not just the eigan values, I wrote another script that just copies the line of the search result (CP # 423) and the next 32 lines to a variable by way of ui scripting.
So what I’m asking is how to change the selection to relatively known objects (sometimes lines, sometimes strings of text) in the file (I also tried identifying the line # of the search result, but I’m just no good), and from there how to directly set the value of a variable to the selected text (I assume "set variable_ to selection as (text or whatever).
PS I’d also like to do this using pages, word, textedit, or any other scriptable text editor or word processor.
Here’s an example of the kind of text I’m working with:
CP # 423
CP COORDINATES: 3.273403 0.072249 1.034378
EIGENVALUES OF HESSIAN MATRIX:
-0.6777485E+00 -0.6772667E+00 0.5110175E+00
EIGENVECTORS (ORTHONORMAL) OF HESSIAN MATRIX (COLUMNS):
0.9029738E+00 0.2339380E+00 -0.3604321E+00 -0.4256971E+00 0.6011940E+00 -0.6762749E+00 0.5848318E-01 0.7640934E+00 0.6424492E+00
VALUES OF SOME FUNCTIONS AT CP(a.u.):
Rho = 0.2617350E+00 |GRAD(Rho)| = 0.2565964E-13 GRAD(Rho)x = -0.2297099E-13 GRAD(Rho)y = 0.1136114E-13 GRAD(Rho)z = 0.1294321E-14 Laplacian = -0.8439977E+00
(-1/4)Del**2(Rho)) = 0.2109994E+00
-0.5232880E+00 0.2898309E+00 -0.2751837E+00 -0.1338949E+00 -0.5162645E+00 -0.1868148E+00