I want to select a paragraph at the time.
key code 121 takes me to the beginning and 123 takes me to the end of that line.
However it simply goes there
How do create a selection from these two insertion points?
this is what I figured out
set theFile to choose file of type "rtf"
tell application "TextEdit"
open theFile
activate
tell application "System Events" to tell process "TextEdit"
key code 121
delay 1.5
key code 123 using shift down
end tell
end tell
I can’t help you with this, but I can tell you that you struggle a lot with scripting TextEdit like this.
GUI scripting is hard enough if it is used in a fairly static context, yours is highly dynamic.
It is one of the greatest apps you can have on a mac if you script AppleScript! Provided you use usb and an appropriate micro controller interfaced with your dish washer, you’d have it do that too! Your struggling would at least be over in a breeze! -And believe me, you will struggle all the way!
I hope for your own sake, just download Tex-Edit Plus and run the demo scripts, then look at the source. If you don’t like, then put in the trash, but please do try it.
It will save you a lot of time. And there is even a whole site with great scripts at dougscripts.com199 Surely great scripts to look at -I have looked at a few, and they are very easy to follow!
I used Tex-Edit when Mac was still system 5 and there was no multitasking yet (AKA one application and the Finder ONLY) and perhaps you where not even born. I know all about it.
However, honestly speaking, TextWrangler is a better (plain text only) app than Tex-Edit even if it doesn’t understand rtf. For plain text it has no rivals.
Rtf in TexEdit is not as powerful as it is in Apples Text Edit: several routines in this app come from various other sources sand developers. Rtf and unicode among them. So scripting while easier than Apples app as it allows recording scripts easily, (yet TextWrangler is better for plain text and free) does not work properly for what I need in this and other specific cases. Why? because when recording scripts involving Unicode and RTF it returns weird results when it does return anything at all. Trust me I am very stubborn while I try to solve problems, and I spend time to find solutions before running for help and taking people’s time.
However I find rather surprising the following: while it’s easy to select the cut and paste things like Quicktime files in Text-Edit I get no suggestions. In this group or googling around.
In any case at my age (72) I am too old to go through Applescript manuals … I tried but I admit my limits. While I really appreciate your time in suggesting anything at all, please never mention Tex-Edit again because I know this app. Paid the fee, wrote to Tom the developer and everything else I could think about for this app. It just can’t help me.
Text wrangler is a great text editor for plain text. I agree. I guess if you are stubborn enough you will succeed!
But have you considered Word at all? It is well documented.
If you insist: there should be some posts here about using Gui scripting search for Kai Edwards, that will bring you closer with Text Edit.
Well I looked around a bit and found this scripting example by Kai Edwards which I hope you will find useful. Some of Kai’s original code from that post
activate application "TextEdit"
tell application "System Events" to tell text area 1 of scroll area 1 of window 1 of process "TextEdit" to if exists then
set {x, y} to value of attribute "AXSelectedTextRange"
if x ≤ y then tell application "TextEdit" to set color of document 1's characters x thru y to {0, 0, 65535}
end if
I would have tried something like this: This wont work, it is just as a concept:
set x to character pos 1
set y to end character pos
set value of attribute "AXSelectedTextRange" to {x, y}
Living in the assumption that attribute “AXSelectedTextRange” is not read only
Or maybe just simulating shift being pressed down while you move from on end of the line to the other.
EditI forgot to thank you for your information on Tex-Edit:
I’m not used to the luxury of being able to get anything useful by recording a script anyway, so I can live well without that feature.
I totally agree with you that TextWrangler is a very good text editor. It also gives me that “down to the iron” feeling while I’m using the keyboard. (But Tex-Edit plus is a “tad” more responsive though ).
I think you are really a great person and hopes you will succeed with TextEdit and I would love to see your results.
Besides of all of this, I know now about at least one very competent person on Tex-Edit Plus here.