I’ve spent 3 hours trying to set the color of a single word in a text field, to no avail.
Please tell me what I’m doing wrong!
Regards
Santa
if theObjectName = "InitialPrinterList1" then
set temp to "This printer will print the rtfd's, Excel & Word documents. REMEMBER! For all the printers set in this application, corrosponding print presets must be set in each printing application."
set content of text field "Help" of theWindow to temp
set textRef to a reference to (text view "Help" of text field "Help" of theWindow)
set text color of word 11 of textRef to {60000, 1, 1}
end if
EDIT. This doesn’t crash, but doesn’t do anything either. And how do I set it to change color?
if theObjectName = "InitialPrinterList1" then
set temp to "This printer will print the rtfd's, Excel & Word documents. REMEMBER! For all the printers set in this application, corrosponding print presets must be set in each printing application."
set content of text field "Help" of theWindow to temp
set fontDone to {"Times", 18}
set positionOfWord to 11
set excerciseTextView to (contents of text field "Help" of theWindow)
call method "setFont:" of (excerciseTextView's word positionOfWord) with parameter (call method "fontWithName:size:" of class "NSFont" with parameters fontDone)
end if
if theObjectName = "InitialPrinterList1" then
set temp to "This printer will print the rtfd's, Excel & Word documents. REMEMBER! For all the printers set in this application, corresponding print presets must be set in each printing application."
set string value of text field "Help" of theWindow to temp
set textRef to a reference to text field "Help" of theWindow
set positionOfWord to 11
call method "setTextColor:ofString:inTextField:" of class "SKText" with parameters {{1.0, 0.0, 0.0}, word positionOfWord of temp, textRef}
end if
Note:
the three parameters of the method are the color (a list of three float values between 0.0 and 1.0 in order R G B), the string to be colored, and the reference to the text field
This might just be what I am looking for, finally!
I am trying to modify it to fit my needs. I want to have every certain words such as “Pass” and “Fail” have a different color. In my AppleScript I did this:
set textRef to a reference to (text view “detailed results” of scroll view 1 of drawer “drawer” of window “main”)
call method “setTextColor:ofString:inTextField:” of class “SKText” with parameters {{0.0, 1.0, 0.0}, “Pass”, textRef}
call method “setTextColor:ofString:inTextField:” of class “SKText” with parameters {{1.0, 0.0, 0.0}, “Fail”, textRef}
However, I seem to be getting a handler error. Any ideas what I may be doing wrong?
Thanks so much StefanK! I really appreciate all your posts on this forum as I have seen many other useful ones come from you.
}[/code]
using your example keywords, you can call the method with
set viewRef to a reference to text view "textView" of scroll view "scrollView" of window "main"
call method "setTextColors:OfStrings:inTextView:" of class "SKText" with parameters {{{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}}, {"fail", "pass"}, viewRef}