1-chose a whatever.rtf file
2-select the first paragraph
3-pause the script
4-perform some actions manually on that paragraph
5-move to the next
6-Exit from the script at the last paragraph
This is what I did and it always tells me Invalid index
set theDoc to choose file with prompt "Select:"
tell application "TextEdit"
set theDoc to document 1
set parag to (count of paragraphs of text of theDoc)
repeat with i from 1 to parag
set Para to parag - 1
repeat with i from 1 to Para
select paragraph Para of theDoc
end repeat
end repeat
end tell
Hello there is some errors in your script, I tried to run it just for the fun of it.
I think select is a reserved word in ApplesScript without any support as a command in TextEdit, at least not under Snow Leopard.
TextEdit has a rumor for being notoriously hard to script. I recommend you use another editor for Scripting rtf-text Tex-Edit Plus is shareware and can easily be found by Google. It will even be able to wash your dishes if you have a micro controller and a washing machine that supports it!
If don’t want to spend that kind of money . cheap! Then you should use MS word if you have that available. I don’t know anything about pages, but that might be an alternative as well.
Here is your script with some editing until we came to the selection.
set theDoc to choose file with prompt "Select:"
tell application "TextEdit"
set theDoc to document of window 1
set parag to (count of paragraphs of text of theDoc)
repeat with i from 1 to parag
set Para to parag - 1
repeat with i from 1 to Para
select its paragraph Para of theDoc
end repeat
end repeat
end tell
Shouldn’t there at least to be a line like ‘open theDoc’, because nothing gets opened.
set theDoc to choose file with prompt "Select:"
tell application "TextEdit"
open theDoc
set theDoc to document of window 1
set parag to (count of paragraphs of text of theDoc)
repeat with i from 1 to parag
set Para to parag - 1
repeat with i from 1 to Para
select its paragraph Para of theDoc
end repeat
end repeat
end tell
Hello
Now that would give the word “out-sourcing” new meaning wouldn’t it?
Joke aside, I can’t. Or I could if I didn’t do much else for a couple of months. I have to learn Objective C first.
Then there is the construction of AS Dictionaries. And I’m sure : a couple of other things to. But it would have been an interesting project.
I once wrote a script for VoodooPad to highlight selected text, I tried then to us this scripting example by Kai Edwards to manage it. But I really didn’t manage it. -It was such a pain. it turned out that VoodooPad pro didn’t support the clipboard, so I had to gain access to the clipboard through SystemEvents via a Folder Action!
The script activated via a folder action:
tell application "VoodooPad Pro"
activate
tell application "System Events" to keystroke "c" using command down
end tell
tell application "TextEdit"
activate
make new document at front
tell application "System Events" to keystroke "v" using command down
tell the text of document 1
-- set the color of every word to {0, 65535, 0} -- green
--set the color of every word to {65535, 0, 0} -- red
set the color of every word to {0, 0, 65535} -- blue
end tell
tell application "System Events" to keystroke "a" using {command down}
tell application "System Events" to keystroke "c" using {command down}
close document 1 saving no
-- You may want to comment out this if you ever should doubt what is happening
end tell
tell application "VoodooPad Pro"
activate
-- so you may have to increase the delay if the text isn't rendered into your document.
-- as stuff then, (the keystrokes are happening to fast for voodoopad to react )
delay 1
tell application "System Events" to keystroke "v" using {command down}
end tell
I figured, I’d would have been much better off learning Python, because it was doable via Python to achieve the same, but I was to giddy to fix the broken Python installation.
But I wonder if I could write a new x and y value to the AXSelectedTextRange and set a selection that way, through System Events in TextEdit.