Clipboard issues [SOLVED]

I'm experiencing 2 issues with the clipboard and I can't find a way to work around them:

1 - It seems that when I copy a file in Finder to the clipboard, for example a Numbers spreadsheet, in the clipboard history it seems to sometimes show me the path, but sometimes the file itself, making it hard to use certain actions that rely on checking if the clipboard contains a path. This is the exact file and you can see that the first time I hit CMD+C it copied it as a path, but the second time it shows the image, so if I'm using an IF THEN action to check if the clipboard starts with ~/ or /Users/, sometimes it would be true and sometimes false:

Clipboard not consistent

2 - It seems that clipboard sometimes see certain file names as a password (I guess that's the issue here) so if I have a file with a specific type of name and I try to apply certain actions, it will result in it being false such as this example below where the red rectangle is the file name and the yellow rectangle is what the clipboard sees:

image

How can I work around these issues?

In Finder, if you hold down the Option key, you can select Edit > Copy [selected thing] as Pathname. Can you test to see if that gets around the issue with the clipboard? If it does, then you just have to have KM do that for you.

-rob.

Yes, I do that all the time, but for this particular case, I need to use a simple "Copy". Let me explain, for context:

I use Obsidian and for some reason when I use the Paste and Match Style option when copying a file in Finder, it doesn't work the same way the Notes app does, which pastes the file name. In Notes, this works as expected whether it's a single file or multiple files.
Obsidian simply doesn't work at all. I already started a thread on their forum, but it seems to be an issue with the app itself.

So I'm building a macro that fixes it, but I can't seem to find a way to do it.

What happens if you paste the copied Numbers icon into TextEdit in plain text mode? Do you get a path?

-rob.

Don't know what you mean by "Name Mangler", but if I hit CMD+C on a file and then paste it (CMD+V) on a TextEdit document set to plain text, I get the name of the file (not the path) as displayed in Finder, meaning that if the extension is visible, I get the name + extension, but if the extension is hidden, I only get the name.
This works the same both for a single file or multiple.
image

I see that you edited your reply. Maybe this is what you meant?

So I hit CMD+C a few times until it showed me the icon, instead of the path. Then selected "Paste" from the Clipboard History itself and I got the file name, not the path

When you "Copy" in the Finder a whole bunch of stuff goes on the clipboard -- what gets Pasted depends on context and, particularly, what the app you are pasting into will accept. Obsidian seems to treat a standard Paste as "paste a file link" but Paste and Match Style as "paste the file's preview image".

So what is it you want to paste into Obsidian -- file name, path, something else? And why "match style" in the first place (not a big Obsidian user, so not entirely sure what that achieves!)?

Yep, that's being considered a password, so hidden. You can turn that off completely (KM Settings -> General -> Detect (and Conceal) Possible Passwords) or you can add patterns that shouldn't be treated -- search for "Regular Expression Which Matches Text You Think Should or Should Not Be Concealed as Passwords" section in the manual. A pattern of "ends with a period followed by 3 to 5 letters or numbers" will probably do you.

Sorry, mental typo as I was doing tech support in another tab :).

OK, that's expected—I was curious if you had any text data with the icon in your screenshot or not—the clipboard switcher indicates it's a picture, so I wasn't sure.

In testing here, I figured something out, but I'm not sure if it's helpful or not. If I do this:

Finder Copy - Invoke Clipboard History Switcher

Then I get the filename. But if I do this:

Finder Copy - Wait one or two seconds - Invoke Clipboard History Switcher

Then I always get the icon.

I'm not sure I understand how a regular copy gets around this problem? (I'm not a regular Obsidian user, so that's part of the problem.) In either case, is your objective the filename or the path?

-rob.

Thing is: "Paste" actually copies the file to Obsidian's vault, not just a link to the original location (not sure if that's what you mean?). But "Paste and Match Style" doesn't do anything at all. Not even a file's preview. It simply doesn't work.

What I'm trying to achieve (and this also answers your question @griffman) is to paste the name. Sometimes I need to select a bunch of files in Finder and paste them somewhere just as file names so I can then take notes or things like that.

I remember turning that off a while ago when I was experiencing a similar issue. Maybe KM turns that on automatically when we update to a new version?
What's weird is that now that I was trying to copy that same file, even with the setting turned on, I wasn't getting that same behavior. I'm back to just seeing the path or the icon. Weird...

But would this action be effective if the clipboard already contains the filename?
What I mean is: I hit CMD+C and then I run the macro with that RegEx. Will KM be able to access the original file name, since it seems to already hide it? Hope it makes sense what I'm trying to ask?

That happens sometimes, yes haha

I don't experience that. Closed the Clipboard History, copied the file, opens Clipboard History again. I get the icon.
If I right click the icon and pick "Remove Style", I get the file name. Not sure if this helps?

Then, rather than trying to fight Obsidian, the clipboard, and any mis-matches with your slightly-out-of-date OS, write a macro that copies the names of the items in the current Finder selection and formats that text the way you want, ready to paste into Obsidian.

Again, contextual determination of clipboard contents. Your file name looks like a password, a path or image won't. How/why KM sees the same collection of clipboard contents as different things in different situations is beyond me, though!

It's a hidden KM preference, not something you'd do within the macro. Read the manual for more.

Ok I think I got it working. Tested with different files, one file vs multiple files selected, when it was showing the path, when it was showing the icon. It seems to be working in all scenarios:

image

2 Likes

Here's something you may already have but, if not, may find useful. It'll paste file:// links for the Finder's current selection into Obsidian, one per line and each postfixed with :%space%, then move the insertion point back to the end of the first line ready for you to add text.

Nothing added to the vault, but still the ability to open files with a single click.

Paste Links to Selected Files into Obsidian.kmmacros (4.4 KB)

Image

Thanks for sharing.
Obsidian allows this automatically when you move a file (or multiple files) to a note while holding OPTION

image

Maybe your macro can be useful for people who use the Notes app?

Which is what I usually do. But a lot of people here seem like running apps full screen rather than side-by-side (would require a drag to the Dock to activate), Option-dragging adds images when there are image files (I don't want if this is just a nudge about related items), you can add your own automatic formatting (like the :%Space% after each here, or I usually add them as bullet points), etc.

I see how the macro can be useful. I never really liked the full screen feature, so using the OPTION key is perfect, even though I don't think I've ever really created that kind of link. At least, not yet.

I was just testing it and all you have to do is remove the ! from the beginning.
ZIP file:
image

Image file, with direct drag and drop with OPTION (inserts image as well, because the ! indicates an embedded item - image, video, etc):
image

Once you remove it, no more image:
image

You can also use Obsidian's "Replace":

...which works in "Preview" as well as in "Source" mode. Include the [ if, like me, you litter your notes with exclamation marks!