Groups | Search | Server Info | Login | Register
Groups > comp.databases.filemaker > #3544
| From | Martin Τrautmann <t-usenet@gmx.net> |
|---|---|
| Newsgroups | comp.databases.filemaker |
| Subject | Re: Script to Format Selaction in a Text Field |
| Date | 2025-05-27 15:30 +0200 |
| Organization | slrn user |
| Message-ID | <slrn103bfj2.4je.t-usenet@ID-685.user.individual.de> (permalink) |
| References | <0001HW.2DE5299B01544BBC309C3E38F@news.astraweb.com> <slrn103ao6r.4je.t-usenet@ID-685.user.individual.de> <0001HW.2DE5E40D017FFE57306CF638F@news.astraweb.com> |
On Tue, 27 May 2025 08:14:05 -0400, Jack Nastyface wrote: > 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: Nevertheless good to know that chatGPT does some decent work >> # 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 ) ] well chosen and documented >> 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 ( > $selected ; RGB ( 255 ; 0 ; 0 ) ) & $after ] >> Set Field [ YourTable::YourTextField ; $coloredText ] Here's a certain weakness since it does work on a certain field only. The approach which I suggested would work on any field you are currently in. But you could script to set the active field name for another variable and select the field then again. >> Else >> Show Custom Dialog [ "No Text Selected" ; "Please select some text in the field before running this script." ] >> End If One of the options. Instead you might use a dialog to cancel or do the operation on the full text instead. >> 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 ] a typical and minor mistake, solved easily by debugging. You now might google some of the script steps whether this good solution had been written by someone else before. Obviously, this solution here does apply colors only, while there are other formatting options, too. So thanks for the chatGPT hint - this might simplify future script editing if you can copy/paste those scripts directly. How well does it work if you tell chatGPT to translate that script for German language setup? :-)
Back to comp.databases.filemaker | Previous | Next — Previous in thread | Find similar
Script to Format Selaction in a Text Field Jack Nastyface <nowhere@noplace.com> - 2025-05-26 18:58 -0400
Re: Script to Format Selaction in a Text Field Martin Τrautmann <t-usenet@gmx.net> - 2025-05-27 08:51 +0200
Re: Script to Format Selaction in a Text Field Jack Nastyface <nowhere@noplace.com> - 2025-05-27 08:14 -0400
Re: Script to Format Selaction in a Text Field Martin Τrautmann <t-usenet@gmx.net> - 2025-05-27 15:30 +0200
csiph-web