10 Replies Latest reply on May 11, 2015 1:26 AM by wimdecorte

    How to use pbcopy to copy a field to clipboard

    macrolide

      Am trying to use the Perform Applescript script step to copy an ID of a record to the clipboard.

       

      Having problems with this code:

      pbcopy.png

       

      Could anyone suggest a fix?

        • 1. Re: How to use pbcopy to copy a field to clipboard
          markp

          You could try this

           

          "tell application \"Finder\"¶set the clipboard to \""

          & Get ( RecordID ) &

          "\" as string¶end tell"

          • 2. Re: How to use pbcopy to copy a field to clipboard
            macrolide

            Brilliant. Thank you.

            • 3. Re: How to use pbcopy to copy a field to clipboard

              Copy to the clipboard is a native function in FileMaker and AppleScript is not needed unless the AppleScript clipboard is unique and you will use that in another AppleScript..

               

              You can use the COPY function built into FileMaker which will copy the contents of the designated field or if none is designated all of the fields in the record. Check the help file. The copy is made to the clipboard.

               

              Go to layout

              Go to record

              Copy(table::field)

               

              I was able to copy a field and paste it into Word using Command+V.

              • 4. Re: How to use pbcopy to copy a field to clipboard
                wimdecorte

                Two things:

                - what's wrong with the FM "copy" script step?

                - in coding it is considered bad form to destroy the user's clipboard

                • 5. Re: How to use pbcopy to copy a field to clipboard

                  How would the FM Copy function differ from the AppleScript copy in that regard?

                   

                  I seem to recall that a plugin would save the user's clipboard and then reinstall it later. Of course you could save it to a container field, maybe?

                   

                  And giving the user a warning and then the option to proceed would be a good idea.

                  • 6. Re: How to use pbcopy to copy a field to clipboard
                    leish2

                    If you use Copy and/or Paste in Filemaker you should probably capture the contents of the OS clipboard before doing any Filemaker copy/paste and then put it back after you do your FileMaker copy/paste.

                     

                    The script might look like the picture attached.

                     

                    FMP Copy Paste script.png

                    • 7. Re: How to use pbcopy to copy a field to clipboard
                      wimdecorte

                      jackrodgers wrote:

                       

                      How would the FM Copy function differ from the AppleScript copy in that regard?

                       

                       

                      Which of my two bullet points where you replying to?

                       

                      Using the native FM copy script step is going to be much less fragile than going out to the OS to do the same thing.

                      If you were referring to the 2nd point about it not being polite to destroy the user's clipboard; then either approach would be equally bad unless you go to the extra length of trying to restore it.

                      • 8. Re: How to use pbcopy to copy a field to clipboard

                        One point to consider is that Copy is only needed if data in a FMP field is being copied in order to paste it into another application such as Word. It is not needed to do things in FileMaker only, is it? You can set the contents of a field into a variable or global and then set that into another FileMaker area.

                         

                        So, if the user wants to click a button to copy a field and then paste that into Word, they've already OKed overwriting their clipboard.

                         

                        I remember using applications that created multi-clipboards whose contents could be saved to a file...oh, like FileMaker?

                         

                        If clipboard contents are an issue, create your own Clipboard table and paste the contents in a suitable field. Your user can then create and save an unlimited number of cli[boards, right?

                        • 9. Re: How to use pbcopy to copy a field to clipboard
                          sporobolus

                          On 2015-05-07 19:07 , jackrodgers wrote

                          So, if the user wants to click a button to copy a field and then paste that into Word, they've already OKed overwriting their clipboard.

                           

                          to expand on Wim's point, a button generally won't tell the user clearly

                          that they'll lose their clipboard contents; in fact many users don't really

                          understand that there's a "clipboard" underlying their use of copy & paste,

                          but they still count on the functionality

                           

                          so as a general rule, a script should only use the clipboard to transfer

                          information as a last resort

                           

                          my 20-year relationship with Microsoft Word ended a while ago, but i'm

                          pretty sure you can still use AppleScript to insert text into a Word

                          document without using the clipboard

                           

                           

                          If clipboard contents are an issue, create your own Clipboard table and paste the contents in a suitable field. Your user can then create and save an unlimited number of cli[boards, right?

                           

                          no, the OS X clipboard stores a variety of object types that can't be saved

                          into FileMaker fields

                          • 10. Re: How to use pbcopy to copy a field to clipboard
                            wimdecorte

                            steve harley wrote:

                             

                            my 20-year relationship with Microsoft Word ended a while ago, but i'm

                            pretty sure you can still use AppleScript to insert text into a Word

                            document without using the clipboard

                             

                             

                             

                            Yes you can.  Same on Windows through Word's ActiveX / COM.  It's what it is there for.  Granted, a little more work but ultimately a lot more elegant and robust.