3 Replies Latest reply on Jun 14, 2010 8:35 AM by philmodjunk

    Script to move selected text from one field to the next

    JosephB

      Title

      Script to move selected text from one field to the next

      Post

      Hello

       

      Newbie here, first post, thanks in advance. 

       

      I would like to set up a script that copies user-selected text from one field in the layout to a new, related record in a portal on the same layout.  A user would select some text with the mouse, hit a button, and that selected text would show up in the target field.  

       

      I am ok with the script as far as pointing to one field or another, and setting up the button to run the script, but I can't seem to figure out how to get filemaker to "pick up" or "copy" text as selected by the mouse. 

       

      I have tried to do this with SetField, insert text, and a few stabs at an applescript, but I keep ending up at the calculation dialogue, and can't figure out what calc would get me the selected text. 

       

      Ideally I would avoid using the clipboard but I will if that is the only way. 

       

      Thanks!

       

       

       

      Thanks

        • 1. Re: Script to move selected text from one field to the next
          Steve Wright

          Try something like the following, which should give you the selected text in the field, which you can then use in the script 

           

           

          Set Variable [ $selection ; 
          Middle( Table::Field ; Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionSize )) 
          ]

          You can then Set the appropriate related field using Set field [ related::field ; $selection ]

           

          There may be other ways, but this one came to me first.

           

           

          • 2. Re: Script to move selected text from one field to the next
            JosephB

            Hey, thanks so much for responding.  Well, I have made a workaround by just doing two super-simple buttons in the layout.  One copies selected text to clipboard, the other pastes to the designated field.  I tired using the snippet you sent which I couldn't get working.  FM kept telling me that it couldn't find my table (I substituted my table  and field names in for the placeholder you sent).  Looks like my two-button solution is going to be more flexible anyhow. 

            • 3. Re: Script to move selected text from one field to the next
              philmodjunk

              What version of filemaker are you using? The above example by SWS should work for you.

               

              A minor detail that I often leave out myself is that it should really look like this, when you view it in manage scripts:

               

              Set Variable [ $selection ; Value:  Middle( Table::Field ; Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionSize )) ]

               

              (Value: is added by filemaker, you don't type it in.)

              If you add Table::Field to your expression by finding it in the field list and double-clicking it to add it to your expression, you shouldn't see this error message.

               

              Using copy and paste in any script is usually the less ideal approach as it replaces any text the user may have previously copied to the clipboard with the selected text and this can irritate/inconvenience your users.