3 Replies Latest reply on Jul 24, 2013 8:51 AM by K.Daube

    Manipulating the clipboard

    K.Daube Level 1

      I wanted to set up a command and shortcut to surround clipboard contents by [[ and ]] before pasting.

      The purpose is to insert temporary citations which are put into the clipboard by an external application (EndNote).


      The method mentioned in discussion Can I pull clipboard contents into a script variable is more than clunky: use a file as an intermediate.


      On the other hand in AutoHotKey it is very easy to manipulate the clipboard. I have even used it to make code-coversions on the fly.

      ^y::                                    ; {LaBonté, 1989 #11}
        Transform, utfString, Unicode         ; Retrieve the clipboard's Unicode text as a UTF-8 string
        StringTrimLeft, utfString, utfString, 1 ; remove EndNote's braces
        StringTrimRight,utfString, utfString, 1
        utfString := "[[" . utfString . "]]"  ; sourround with double brackets
        Transform, Clipboard, Unicode, %utfString%
        Send, ^v                              ; [[LaBonté, 1989 #11]]

      Hence I decide to keep this function outside of the script and will invoke the AHK script (converted to an exe) at the start of the script. This will establish the shortcut for the function.

        • 1. Re: Manipulating the clipboard
          K.Daube Level 1

          Something very strange happens:

          $.includePath generates a string ending with a semicolon, for example:


          Hence the following does not find and execute my compiled AHK script

          // establish the hortcut for inserting temp. citations with the AHK scipt
            var ahkFile = File($.includePath + "\\ctrl-y.exe");
            if (ahkFile.exists === true) {
            } else {
                 alert ("Program ctrl-y.exe not found in script directory");

          OK, I just need to add some code to remove the semicolon. But why the heck is it there?

          • 2. Re: Manipulating the clipboard
            4everJang Level 3



            If I understand it correctly, you want to put a citation from the clipboard into your FM document by pasting, but the pasted text should have double angle brackets around it to make it show up as a citation. I would think that the easiest solution would be to have a script for "Paste as citation" instead of trying to tweak the clipboard contents before pasting it. The "Paste as citation" simply pastes whatever is in the clipboard to the text location and then adds the double angle brackets. Adding the "Paste as citation" command to the Edit menu is not a big deal and you can define your own shortcut to invoke the command.


            Would this not be much easier than changing the cilpboard contents ?


            Good luck



            • 3. Re: Manipulating the clipboard
              K.Daube Level 1


              Thank You for this idea. Since the clipboard is filled by another application (EndNote), I thought that the method i have used in previous vesion of my utility would be adequate.


              With the vary same method (an AHK script) I have establisehe some texthelpers (see http://www.daube.ch/docu/fmaker69.html) which are handy not only in FM.