I want to color some text in a text field using a script but I can’t figure out a way to do it. There doesn’t seem to be an applicable script step. Any ideal?
On Mon, 26 May 2025 18:58:35 -0400, Jack Nastyface wrote:
I want to color some text in a text field using a script but I can’t figure
out a way to do it. There doesn’t seem to be an applicable script step. Any
ideal?
You want to select some part of the text only?
# Assumes the field is named "YourTextField"$selected ; RGB ( 255 ; 0 ; 0 ) ) & $after ]
# Make sure to enable "Select entire contents" is OFF in the field settings
# This only works if the field s active and the user has selected text
Set Variable [ $start ; Value: Get ( ActiveSelectionStart ) ]
Set Variable [ $size ;Value: Get ( ActiveSelectionSize ) ]
Set Variable [ $text ; Value: Get ( ActiveFieldContents ) ]
If [ $size> 0 ]
Set Variable [ $before ; Value: Middle ( $text ; 1 ; $start ) ]
Set Variable [ $selected ; Value: Middle ( $text ; $start + 1 ; $size ) ]
Set Variable [ $after ; Value: Middle ( $text ; $start + $size + 1 ; Length ( $text ) ) ] Set Variable [ $coloredText ; Value: $before& TextColor (
Set Field [ YourTable::YourTextField ; $coloredText ]
Else
Show Custom Dialog [ "No Text Selected" ; "Please select some text in the field before running this script." ]
End If
Notes: Replace YourTable::YourTextField with the actual table and field name. This script assumes the field is being edited when the script is triggered. For rich text, this formatting will apply and be visible if the field supports styled text (e.g., a Text field on a layout).
Set Variable [ $start ; Value: Get ( ActiveSelectionStart ) -1 ]Jack
Martin, thank you so much for your reply. I wasn’t sure anyone was still monitoring this group :) Yes, I want to only select a part of the text. While I was waiting for a reply, I asked chatGPT to write a script for me. The result does exactly what I wanted. However it had an “off by one” error in it. LOL Nice to know chatGPT makes those kind of errors too. Here is the script:
# Assumes the field is named "YourTextField"
# Make sure to enable "Select entire contents" is OFF in the field settings >> # This only works if the field s active and the user has selected text
Set Variable [ $start ; Value: Get ( ActiveSelectionStart ) ]
Set Variable [ $size ;Value: Get ( ActiveSelectionSize ) ]
Set Variable [ $text ; Value: Get ( ActiveFieldContents ) ]
If [ $size> 0 ]$selected ; RGB ( 255 ; 0 ; 0 ) ) & $after ]
Set Variable [ $before ; Value: Middle ( $text ; 1 ; $start ) ]
Set Variable [ $selected ; Value: Middle ( $text ; $start + 1 ; $size ) ]
Set Variable [ $after ; Value: Middle ( $text ; $start + $size + 1 ; Length ( $text ) ) ]
Set Variable [ $coloredText ; Value: $before& TextColor (
Set Field [ YourTable::YourTextField ; $coloredText ]
Else
Show Custom Dialog [ "No Text Selected" ; "Please select some text in the field before running this script." ]
End If
Notes: Replace YourTable::YourTextField with the actual table and field name.
This script assumes the field is being edited when the script is triggered. >> For rich text, this formatting will apply and be visible if the field supports styled text (e.g., a Text field on a layout).
The “off by 1” error is in the first line which should read
Set Variable [ $start ; Value: Get ( ActiveSelectionStart ) -1 ]
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 490 |
Nodes: | 16 (2 / 14) |
Uptime: | 69:48:10 |
Calls: | 9,678 |
Calls today: | 2 |
Files: | 13,722 |
Messages: | 6,172,121 |