Hello!
I have a text that I use as a to do list. I have structured it over time, and I now use a system like this:
x JOB1: task one
x JOB1: task two
v JOB1: task three
pending JOB2: task one
Using TextEdit feels natural & lightweight and the x-y thing is fairly quick to manage, but I thought it would be nice if the x lines (or paragraphs) where colored in red, and the y lines in green, so a quick glance over the text could tell me what needs to be done.
I’ve found some examples here and there but I seem unable to construct a complete script. Here are two scripts that come close:
TextEdit: Change color of a selection (script from Kai: http://macscripter.net/viewtopic.php?id=20860 )
tell application "System Events" to tell text area 1 of scroll area 1 of window 1 of process "TextEdit" to if exists then
set {startSelection, endSelection} to value of attribute "AXSelectedTextRange"
if startSelection ≤ endSelection then tell application "TextEdit" to set color of document 1's characters startSelection thru endSelection to {65535, 3858, 0}
end if
tell application "TextEdit"
activate
end tell
TextEdit: Search and replace (script from John Steward: http://forum.soft32.com/mac/find-replace-TextEdit-ftopict39169.html )
Cool, but the replace string can’t store color information.
tell application "TextEdit"
set text of document 1 to my doRplc(get text of document 1, "search string", "replace string")
end tell
on doRplc(txtStr, srchStr, rplcStr)
set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {srchStr}}
set temp to every text item of txtStr
set AppleScript's text item delimiters to {rplcStr}
set txtStr to temp as text
set AppleScript's text item delimiters to oldDelims
return txtStr
end doRplc
I thought of the following procedure:
- search for “x (tab) (tab)”
- if found: get position of file pointer
- color the paragraph (where the file pointer is in) red
- go on to the next find of "x (tab) (tab)
…
Ideal would be a search and replace ‘with rich text formatting’, so one could replace with another color.
I’m sorry to ask this, but I seemed to get stuck here.
Thanks
Elias