Ulysses - No Text in Clipboard

So, to cut the long story short: What is the culprit for the “No Text in Clipboard”?

In the text samples above, adding one more paragraph with one sentence breaks the Macro. On the other hand, the same Macro works with much longer text.


This is beyond me. The macro works and it works not?

Yes, KM supports JavaScript for Automation.

See here.

Sorry, wrong answer. Adding one more sentence as a new paragraph broke the macro to No Text in Clipboard

So, you are saying the issue happens when a certain amount of text (number of bytes) is exceeded?

From what I figured so far. Yes.

I’m not sure, but I tend to think that it really has to do somehow with KM.

Maybe KM’s Search action is limited to a certain amount of bytes? I never run into that problem, so I have no clue. Maybe @peternlewis can enlighten us.

Maybe worth to test a macro with copy/paste only (without search/replace)…

To answer my own question: this works fine in Ulysses

So the problem is with replacing clipboard content. There is some kind of limitation in KM? But then why does it work in TextEdit and other apps?

You are right, my thoughts are not really coherent. In macOS there are different clipboard types. The app choses in which format it copies data to the clipboard. Then, what KM can pick up is just what is on the clipboard. So, maybe there’s a glitch somewhere in-between.

But, I just checked it, after copying from Ulysses there is plaintext on the clipboard, as it should be. So, honestly, no idea.

What is the max number of chars/bytes?

Tom, while we are waiting for @peternlewis to look into this, can you please show me how would I pass clipboard content to a Javascript?

I did read the wiki, but I am too new to all of this to figure out how to connect clipboard to java with variables.

This is as far as I got:

Convert Male to Femal Report.kmmacros (5.4 KB)

The required information is here, almost at the end of the Wiki article (don’t ask me why).

So, to get the value of a KM variable:

var kme = Application("Keyboard Maestro Engine");

First, I’d like to request that you be more precise in your terminology. This will help you get better answers faster, and help other avoid wasting time. :wink:

So, what are you actually asking about?

  1. JavaScript in a Browser
  2. JavaScript for Automation (JXA)
  3. Java (a language completely unrelated to JavaScript)?

The terminology that is normally used is:

  • “JavaScript” – when referring to JavaScript in a Browser
  • “JavaScript for Automation” OR “JXA” – when referring to just that.

I’m going to take a guess that you mean JXA, since JavaScript (in a Browser) does not have solid, reliable access to the System Clipboard.

Here is an example JXA script that shows you how to:

  • Get a KM Variable
  • Set a KM Variable
  • Read the Clipboard
  • Set the Clipboard

###Example JXA Script

'use strict';
(function run() {      // this will auto-run when script is executed

  // --- SET CURRENT APP VARIABLE NEEDED FOR DIALOGS & StandardAdditions.osax ---
  var app = Application.currentApplication()
  app.includeStandardAdditions = true

  var kme = Application("Keyboard Maestro Engine");

  //--- GET A KM VARIABLE ---  (remove if not needed)
  //    Returns empty string if it doesn't exist
  var someVarNameStr = kme.getvariable("KMVarNameToGet") || 'Default Value if NOT Found';
  console.log("someVarNameStr: " + someVarNameStr)
  var someNewDataStr = "Text to be set to a KM var";
  //--- SET A KM VARIABLE ---
  //      Creates the Variable if it doesn't exist
  //      Verify Variable in the KM App Preferences
  kme.setvariable("KMVarNameToSet", { to: someNewDataStr });

  var clipboardStr = app.theClipboard()
  console.log("clipboardStr: " + clipboardStr)

  var someDataStr = "Example text to put on clipboard"

  //      Verify using KM Clipboard History Viewer

}  // END of function run()

Please feel free to ask any questions.

When you copy [a selection to the System] clipboard, the app puts on a variety of flavours of data, they might include plain text, rtf, rtfd, proprietary formats, jpg, pdf, png, etc. There are literally thousands of flavours and each clipboard you copy typically has half a dozen or more flavours.

And unfortunately, the formats that applications use are not particularly consistent, and there are a variety of styled formats that are not always mutually compatible. Also unfortunately, Applications do no always put consistent flavours (that is, some of the flavours might represent different text for example).

When Keyboard Maestro reads text from the clipboard, it can do it in one of two ways depending on where the text is going.

It can read it as plain text, looking for the specifically un-styled text formats; or it can read it as styled text, looking for rtf styled formats.

It sounds like in this case, in response to something (probably not text length per se, more likely something in the text, but who knows for sure), Ulysses is putting a different set of flavours in the clipboard. Maybe it is deciding the text is styled a specific way and using some specific format for that.

In any event, there are two things you can try to do to "clean up" the clipboard.

  • Set Clipboard to Plain Text %CurrentClipboard%

Keyboard Maestro will explicitly read the un-styled clipboard flavours.

  • Set Clipboard to Styled Text %CurrentClipboard%

Keyboard Maestro will explicitly read the styled clipboard flavours.

Either way, Keyboard Maestro will set the clipboard with what it considers to be a consistent set of flavours.


Thank your for your reply Peter. After some trial and error I made it work by doing this:

Here is what I do not understand:

  1. How come setting Clipboard to System Clipboard did not do anything but setting it to Default Clipboard did the trick?

  2. I thought that I had to add the option to set the clipboard to plain text after "Cut" and not before it. Why before and not after?

The only thing of relevance that that highlighted action is doing is reading the clipboard.

It might be a clipboard caching issue.

Show the Keyboard Maestro Clipboard History Switcher and watch what it displays.

Hey @slyfox,

Just to make sure – you do understand that the Default Clipboard isn’t really the default?

The real default clipboard is the System Clipboard. The so-called “Default Clipboard” is just another named clipboard (i.e. a variable that holds clipboard data).


1 Like

This has confused many, many KM users, including me. :frowning:
We keep hoping that some day @peternlewis with change the name of this named clipboard. :wink:

1 Like