Display Text works, but NOT as Clipboard for everything TITLE, PATH and TEXT

Display Text works, but the Paste from the clipboard leaves out the file title and path.
What is missing here?

F1 TITLE- PATH and TEXT ⇢ Clipboard.kmmacros (29 KB)

Sorry to report your macro runs fine here on Sequoia. I ran it as you wrote it and then I disabled the pauses and it ran even faster, of course.

I selected some text in BBEdit before running the macro.

I did change the trigger to something on my keyboard but that, and eliminating the pauses, were the only changes I made.

You might peek at the named clipboard to see what's on it.

Update: I assumed you meant you had a problem with Display Text. As I said, all three components were displayed. But if you’re complaining about all three not being in some clipboard for subsequent pasting, the trick is to put all three there to begin with. As written the macro puts two in separate variables from what’s in the named clipboard. So Nige’s approach shows how to resolve that.

You don't, at any time, put the file name and path onto the Named Clipboard.

Try this, and (if it works!) compare its logic to your macro:

F1 TITLE, PATH and TEXT ⇢ Clipboard v2.kmmacros (29.5 KB)

This only displays 1 NamedClipboard, no TTL or PATH.

The intention was to send all of it to the System Clipboard.

This is difficult.

/okn

It works fine if the application you are copying from supports the %FrontDocumentPath% Token. Not every application does.

You can either "Paste from Named Clipboard", "Copy Clipboard to Clipboard" to set the System Clipboard to the contents of the Named Clipboard, or even skip the Named Clipboard altogether and combine your text on the System Clipboard:

My demo only did what your macro did, except correctly. If you want it do something else entirely then you need to state your requirements.

I'm using these core Apple apps: TextEdit, TextSoup, BBEdit and sometimes Pages.
They probably understand the %FrontDocumentPath% Token, and the Local_DocPath & Local_FileName would be fine.

or even skip the Named Clipboard altogether and combine your text on the System Clipboard:

This alternative I tried 5 times, once it worked, otherwise not.

How would one use the

Local_DocPath & Local_FileName

alternative, as set in the original version?

Also, in the original version (see top post) everything looks ok (in the 'Display text'), but I cannot get it into a Clipboard, so it can be pasted into some other file?

/okn

You could guess, or you could test -- I suggest you test. And remember that frontmost document needs to have been saved or the Token will return an empty string.

You combine the text in the "Display" Action, but you never combine it on the clipboard. I showed you how to do that in the v2 macro, and all you have to do is add a "Copy Named Clipboard to System Clipboard" Action at the end of the macro so you can manually Paste later.

OK, so as my punishment for misunderstanding, try this:

Test Macro (v11.0.4)

Test.kmmacros (7.9 KB)

I changed the trigger and the name to test. And I confess Nige's macro didn't produce anything at all on my system.

So I moved the Copy command down. I let the macro peel off the document path and file name before it copied the selected text. That helped.

But I didn't put this in the System Clipboard because I recall reading that the System Clipboard can not be styled. That's a wrinkle. And smoothing it out depends on what you want to do with the styled stuff.

Sorry, these macros don't work, not the original one (1 at top) not (7 see macro below) and not no. (8).

My knowledge is way too limited.

Here is my macro F6 according to what I understood from Mr. Nige_S

F6 TITLE, PATH and TEXT ⇢ Clipboard - based on F1 Macro (v11.0.4)

F6 TITLE- PATH and TEXT ⇢ Clipboard - based on F1.kmmacros (30 KB)

/okn

My macro Test returns these two displays from a selection in BBEdit:

The unstyled one is what happens in the System Clipboard. The second is the styled Named Clipboard.

So, it works, doesn't it?

Yes, it does work at your place.

There must be something else going on here.

macOS Tahoe 26.2, KM latest vs.

Are you on macOS Tahoe?

/okn

You still aren't combining %Local__DocPath% and %Local__FileName% with the Clipboard contents and putting the result on the Clipboard. You were combining them in the "Display Text", but that is only in the dialog that's displayed.

Let's walk through your latest version, assuming that the active document has been saved to /Users/testuser/Documents/file-1.rtf and that in it you have selected the text Hello World!...

  1. The "Comment" Action does nothing
  2. The "Copy to Named Clipboard" Action copies the text Hello World! to the Named Clipboard "Trebuchet 14 Clb"
    Contents of Named Clipboard "Trebuchet 14 Clb": Hello World!
    Local__DocPath: Does not exist yet
    Local__FileName: Does not exist yet
  3. The "Apply Style" Action styles the contents of the Named Clipboard "Trebuchet 14Clb" to 17pt and blue(?)
    Contents of Named Clipboard "Trebuchet 14 Clb": Hello World!, now styled
    Local__DocPath: Does not exist yet
    Local__FileName: Does not exist yet
  4. The "Get Front Document Path" Action puts the path to the front document into the variable Local__DocPath
    Contents of Named Clipboard "Trebuchet 14 Clb": Hello World!, now styled
    Local__DocPath: /Users/testuser/Documents/file-1.rtf
    Local__FileName: Does not exist yet
  5. The "Pause" Action pauses the macro for 1 second
  6. The "Get File Name" Action put the base name of the contents of Local__DocPath into Local_FileName
    Contents of Named Clipboard "Trebuchet 14 Clb": Hello World!, now styled
    Local__DocPath: /Users/testuser/Documents/file-1.rtf
    Local__FileName: file-1
  7. The "Pause" Action pauses the macro for 1 second
  8. The "Display Text" Action is disabled and is not executed
  9. The "Copy Named Clipboard..." Action copies the contents of Named Clipboard "Trebuchet 14 Clb" to the System Clipboard
    Contents of Named Clipboard "Trebuchet 14 Clb": Hello World!, now styled
    Local__DocPath: /Users/testuser/Documents/file-1.rtf
    Local__FileName: file-1
    Contents of System Clipboard: Hello World!, now styled
  10. "Ping!"

Can you now see that at no time in your macro do you combine your variables with the text on either Clipboard?

Both of these versions work for me. Copying from Script Editor and Pasting into TextEdit, on both macOS 15.7.2 and 26.2

The Named Clipboard version:
F1 TITLE, PATH and TEXT ⇢ Clipboard (Named Clipboard).kmmacros (30.2 KB)

Image

The System Clipboard version:
F1 TITLE, PATH and TEXT ⇢ Clipboard (System Clipboard).kmmacros (29.1 KB)

Image

1 Like

No, Sequoia.

1 Like

Both macro versions certainly work now, and a big thank you Nige!

Well, it may surprise you or any reader, but I did not know this step was possible, or I had no idea it existed:

Set System Clipboard to styled text

with all the variables and the clipboard inside!

  1. Question - in the updated version F6 - and the same in F1 upd.
Set System Clipboard to Styled Text
%Variable%Local FileName% o
%Variable%Local_DocPath%
%SystemClipboard%

What is happening here?

First the System Clipboard is styled

and then it is updated with the additional content, correct?

/okn
(This looks better than some other referencing app.)

When using the Set Clipboard to Styled Text action, the plain text tokens in the text will be the style of the text in the action (if you have more than one style across the token, well, you'll get one of them).

So %Variable%Local FileName% will have the style of the text it is written as in the action.

However for tokens (typically clipboards) that contain styled text, that styled text formatting will be used.

Gives:

Peter Lewis - This is a test.

3 Likes

It doesn't surprise me -- while I sort-of knew about it I've never really used it until these macros!

There's an awful lot in KM, so there's always something new to find.

Did the walk-through help at all? Stepping through a macro's Actions like that and keeping track of what is happening and what values are stored where is an invaluable trouble-shooting tool. It's not something, IMO, that can be taught -- but it can be learned if you keep working on it.

1 Like

Agreed!
The walk-through is a necessary tool in my/ our 'KM-toolbox', - first time I saw it.
Especially for macros with many steps, otherwise easy to get lost - at least for the beginner :slight_smile:

1 Like