• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Manipulating the clipboard

Community Expert ,
Jul 04, 2013 Jul 04, 2013

Copy link to clipboard

Copied

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]]
return

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.

TOPICS
Scripting

Views

3.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2013 Jul 04, 2013

Copy link to clipboard

Copied

Something very strange happens:

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

E:\_DDDprojects\FM+EN-escript\escript;

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) {
    ahkFile.execute();
  } 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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 14, 2013 Jul 14, 2013

Copy link to clipboard

Copied

Klaus,

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

Jang

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 24, 2013 Jul 24, 2013

Copy link to clipboard

Copied

LATEST

Jang,

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines