c.Text retrieves incorrect (incomplete) data

I have:

dim c as new Clipboard
dim s as string = c.Text
dim sUTI as string = c.RawData("public.utf8-plain-text")
dim sNSP as string = c.RawData("NSStringPboardType")   ' this doesn't work at all
c.close

I go to Finder, select 2 files and copy.

Clipboard Viewer https://langui.net/clipboard-viewer/ correctly reports the data under the ‘public.utf8-plain-text’ flavor:
00000000: 74 65 73 74 32 2e 74 78 74 0d test2.txt.
00000010: 74 65 73 74 31 2e 74 78 74 test1.txt

I go to Finder, select the same 2 files and option-copy to copy the pathnames. Clipboard Viewer again reports what’s expected (as does pasting into eg BBedit):

00000000: 2f 55 73 65 72 73 2f 70 73 74 /Users/pst
00000010: 79 73 2f 44 6f 63 75 6d 65 6e ys/Documen
00000020: 74 73 2f 74 65 73 74 32 2e 74 ts/test2.t
00000030: 78 74 0a 2f 55 73 65 72 73 2f xt./Users/
00000040: 70 73 74 79 73 2f 44 6f 63 75 pstys/Docu
00000050: 6d 65 6e 74 73 2f 74 65 73 74 ments/test
00000060: 31 2e 74 78 74 1.txt

But my xojo code snippet only retrieves the first path:

(sUTI is also wrong, and sNSP is blank, probably because the “NSStringPboardType” identifier cannot be interpreted, even tho Clipboard Viewer says this flavor is also there).

Looking closely, the 1st Finder copy uses CR (0D) as the delimiter, whereas the path copy uses LF (0A) (why i have no idea).
Conclusion: xojo’s clipboard gets stumped by plain text LFs.

v2024r4.1 on macos

That’s a wild conclusion to jump to without testing end of lines from a known source.

Do you have tests to that effect proving your theory? I’m sick in bed so I can’t test this, but it’s a concerning theory.

Yes, it looks like 0a confuses Xojo and the second path/file is not shown.
Can you create a ticket for this on https://xojo.com/issues ?

For “NSStringPboardType” Identifier, I don’t know enough about this but looking at this documentation:

looks like is not an Identifier (only search hit is under ‘Tags’ column).

Does this apply to any other situation though? Forget Finder files, does it happen with plain text you copy from BBEdit?

No. That text with 0a as LF work correctly in Xojo.

Only happens when you copy Finder files as Pathnames (using Option+Copy). The only reference I have is that ‘Clipboard Viewer’ shows 0a in both cases, so I’m not sure why it fails with Finder files as Pathnames.

That suggests to me that more work needs to be done to extract the Finder copy data correctly.

Yes, a ticket is needed for Xojo to investigate the problem with copying Finder Items as Pathnames.

I don’t think there’s a framework bug here or you would have seen an issue with the tests I asked you to rerun.

Passing different pasteboard types will yield different data back. When interacting with data that’s not yours (like Finder), you sometimes need to investigate how to correctly read it.

If I were at me desk, I could look. The best I can do from bed is pointers.

Another test, I don’t know if it helps:

  • Option Copy 2 finder items
  • Xojo Clipboard code only showing 1
  • Pasted to BBEdit
  • both Items with Pathnames show on BBEdit (2 lines)
  • selected the 2 lines on BBEdit to copy
  • Xojo Clipboard code now shows both

same behavior with 4 finder items, only 1 shown directly from Xojo Clipboard code, all 4 show with BBEdit, select/copy from BBEdit then all 4 show in Xojo.

Edit: I hope you get well soon.

This is probably not what you wanted to hear, but MBS has a solution.

Var p As NSPasteboardMBS = NSPasteboardMBS.generalPasteboard
System.DebugLog(String.FromArray(p.types, EndOfLine))
Var s As String = p.stringForType(p.NSPasteboardTypeString)
System.DebugLog(s)

Yields the following IDE message output:

<time>:public.utf8-plain-text
NSStringPboardType
      : /Users/scott/Project/Some Files/A-ASCII.txt
/Users/scott/Project/Some Files/A-DOSLatin1.txt
/Users/scott/Project/Some Files/A-ISOLatin1.txt

Note: the above list of filepaths are separated by 0A

1 Like

Thx Scott, it’s exactly what I wanted to hear because that’s the solution i came to last nite, but was too tired to post, so you beat me to it. MBS saves the day again.

1 Like

For me, this just means BBEdit puts what you expect in the clipboard, which the Finder didn’t (in other words, the Finder copies data in a way you have yet to understand and pasting and copying using BBEdit turns that to “standard text”).

1 Like

I can confirm this:

But what’s incomprehensible is that the public.utf8-plain-text bytestreams are identical in both cases, both 0A-delimited.
No idea how this could even be possible.

I don’t know if you have access to @Sam_RowlandsAppKit, but in his macOS Declares & External Methods the pasteboard contents are extracted as an NSArray of items (each with potentially one or more flavours).

Maybe the Xojo Clipboard is limited for some reason to the first item in the pasteboard array?

Edited to add: I tested the copying of multiple filepaths in the AppKit app, and each file entry is a separate item in the NSArray. Hopefully that tells us something?

Get well soon Tim!

1 Like

Best wishes, Tim.

The clipboard may hold several flavours at once. So it’s fairly possible it contains both an UTF8 flavour (which is limited to only the first item in the Finder, e.g. if the Finder implements it that way (this easily happens for historical reasons)) and another flavour, that BBEdit knows about and has the ability to paste. Then, when you paste-copy in BBEdit, this is turned as UTF8/plain text only and you see it differently since the clipboard contains a different set of flavours.

yes this must be it, there must be an intermediate step such that public.utf8-plain-text version is created by xojo from what’s on the clipboard, not by the Finder.
So I revise my conclusion: xojo is unable to parse multiline text entries generated by the Finder’s option-copy, whereas BBEdit and TextEdit can, but curiously, Word and Apple’s own Pages cannot.
Clipboard flavors are very different depending on whether you ‘copy’ or ‘option-copy’ multiple items form the Finder.

No, it’s not the end of line.

The data is stored in an array. You have to do work to access that whole array.

That is what I was implying quite a few posts ago.

I do my best not to say “it’s your code” but you’re placing blame in the wrong thing.

1 Like

with all due respect Tim, when BBEdit, TextEdit, ClipBoard Viewer, Curio, GoogleDocs, and MBS are able to extract what I expect (and what actually is) on the clipboard, while Xojo cannot, then I conclude there is a problem with the latter.

I’m sure there are complexities under the hood that account for this anomaly, but the point of Xojo is to insulate us from this, unless we choose otherwise.

When you say “You have to do work to access that whole array.”, sure if ur so inclined, but to me c.Text should do the simple thing it’s supposed to. The above apps seem to know how to do this as expected (admittedly a number of others cannot either). A lot of times yes, “it’s my code” does apply, but in this case i’ll have to disagree.