Copying filenames to clipboard in Big Sur aka WTF

Remoted into my girlfriend’s computer last night to help her. She’s a techophobe and I’m a luddite (still running 10.11.6 for everyday wear and nothing newer than 10.14 except in virtual machines). Her machine is relatively new and came with Big Sur on it.

She had a folder full of new movie files and reason to list them in Excel along with comments and dates and categories. So I said do a Command-A to select all, Command-C to copy, then just paste them in.

It pasted in the freaking movies themselves. Or links to them. Or some other PC-centric weird behavior.

One of the conveniences of MacOS to me has been the built-in “you can copy files and depending on context it will either paste them as files or paste the filenames” feature, whereas on a Windows box you needed to invoke the command line and know your way around pipe character commands with various options just to get the filenames to insert into a document.

So… how does one paste filenames in Big Sur, and also is there a terminal command to switch the behavior back to the classic, and what problem did the developer folks consider themselves to be solving here?

Well you did this in Excel. Which is MS. And that is often the antithesis to Mac ideals. So no surprise the founder of Windows ended up giving you what you so elegantly refer to as “PC-centric weird behavior”.

I just tried what you wanted to do with a built-in Apple app and the files names were pasted. This is not a Mac problem. It’s user error. Error to use good software.

Once you have that list of file names you can always copy past into Excel, if you really must go there.

I suspect the problem is that Excel is a superior weapon of choice for number crunching; it does not handle large text or media files well. There was a lengthy discussion here recently debating the pros and cons of spreadsheets vs. databases:

To quote Sean Connery in The Untouchables, “You don’t bring a knife to a gun fight.” Warning…extremely politically incorrect language and opinions:

TapForms is a relatively inexpensive database app that’s been highly recommended by quite a few TIDbits Talkers.

As said, this is an Excel thing. But, it should be easily remedied: use Paste Special (Cmd-Ctrl-V or Edit / Paste Special) and choose text rather than Unicode.

1 Like

Yeah, this isn’t Excel doing anything really wrong. When you copy from the Finder, you’re putting various different types of data on the clipboard. If you were to stay in the Finder, you could paste those files—the complete files—into another location because that’s the data on the clipboard.

When you paste into Excel, Excel says, “Hey, I can do something with the actual document content, so I will.” The Paste Special > Text approach will force it to just paste text.

If you were to copy and paste into a text-only app like BBEdit, you’d get nothing but text since it would know that it couldn’t do anything else with the rest of the clipboard data.

6 Likes

I opened an Apple text editor on her machine and again tried to copy and paste and it did the same thing.

Just to clarify: what exact Apple application did you use? I’ll make use of it in the future when I’m on Big Sur

Here’s what works for me, albeit on Mojave, but it’s simple to try, so worth a shot on Big Sur. After copying the files, open TextEdit, create a new document, and instead of just doing a Paste, do a Paste and Match Style under the Edit menu (or command-shift-option-V). Paste pastes the file contents for me, while Paste and Match style pastes the file names.

It works that way because TextEdit is doing the same thing Excel is doing. When just told to paste, it takes the “richest” content available on the clipboard, i.e. the contents of the copied files. You have to tell it, like Excel, not to do that, by choosing a different command.

Of course you can always just use Paste Special in Excel as others have said, instead of inserting TextEdit in the middle of the process, but if you have to for some other reason, Paste and Match Styles should work.

2 Likes

It is time to recommend one of my favorite mac utilities. Working with Adobe and Microsoft application, this kind of behaviour I know all about. Sometimes you want it to happen, sometimes you don’t.

There is an app for just this, Plain Clip, and the only thing it does is making all formatting go away from what you have on the clipboard, without getting in the way. It starts, does its job and quit quietly. You can place it in your dock or start it using Spotlight or Butler (or any other trigger you are familiar with.)

https://www.bluem.net/en It has been around for many years. Whatever OS you are using, it will work. It is Free / Donationware.

2 Likes

This kind of problem can be pesky if you’re not aware of how many data types can be stored on the macOS clipboard at once, and is why I always have a good plain text editor on my system.

I run BBEdit 24/7, and while it’s a commercial product it reverts to a freeware “lite” mode after a demo period. Unfortunately these recent versions won’t run on El Capitan.

TextWrangler (the old freeware version of BBEdit) will work on El Capitan, although you might not be able to get your hands on a copy – as it has been twilighted. (I can scare up a copy of v5.5.2 if needed.)

An Apple TextEdit document can be switched to plain-text so that nothing untoward can be pasted into it.

I think you can get a copy of Eddie that will run on El Capitan. It’s very lightweight and powerful for its footprint.

You can always run an AppleScript to gather file names from a selected folder and place them on the clipboard as plain-text.

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/24 21:03
# dMod: 2021/12/24 21:03 
# Appl: Finder
# Task: Extract the Names of Items in the Selected Folder and Place on the Clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Extract, @Names, @Selected, @Folder, @Clipboard
--------------------------------------------------------

try
   
   tell application "Finder"
      set finderSelectionList to selection as alias list
      if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
      set theFolder to item 1 of finderSelectionList
      if kind of theFolder = "Folder" then
         set itemNameList to name of items of theFolder
      end if
   end tell
   
   set AppleScript's text item delimiters to linefeed
   set the clipboard to itemNameList as Unicode text
   
on error errMsg number errNum
   set errMsg to errMsg & linefeed & linefeed & "Num: " & errNum
   if errNum ≠ -128 then
      try
         tell application (path to frontmost application as text) ¬
            to set ddButton to button returned of ¬
            (display dialog errMsg with title ¬
               "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to errMsg
      end try
   end if
end try

--------------------------------------------------------

And you can use the shell for that as well:

'ls' -1 '/Users/myUserName/test_directory/Test_1000' | pbcopy
  • Drag your folder to the Terminal.app.
  • Emplace single-quotes as shown.
  • Add the rest of the command text.
  • Hit return.
  • Paste your content wherever.

-Chris

3 Likes

Strangely, I am not seeing this problem on my Mac (2018 Mac mini, macOS Big Sur 11.6.2, Excel 16.56). I wonder what may be different about our respective installations.

When I copy a bunch of “.mov” files from the Finder, I see the following on the clipboard (using Apple’s clipboard viewer app - part of the Additional Tools for Xcode package):

  • public.file-url - A URL to the first-selected file
  • NSFilenamesPboardType - XML data containing an array of strings, each of which is the full path to a selected file.
  • Apple URL pasteboard type - XML data containing a URL to the first-selected file
  • public.utf16-external-plain-text - The list of filenames (without paths), represented as 16-bit Unicode text
  • public.utf8-plain-text - The list of filenames (without paths), represented as UTF-8 text
  • NSStringPboardType - Looks like the same text as pubic.utf8-plain-text

Plus a few internal-looking types, which appear to be copies of the above.

If only one file is selected, then the clipboard also contains:

  • com.apple.icns - I think this is the selected file’s icon, in the format of an “icns” resource
  • public.tiff - I think this is the selected file’s icon, in TIFF format

When I copy multiple files and paste into Excel, I’m seeing only the filenames. When I do a Paste Special, my choices are:

  • Unicode Text
  • Text

If only one file is copied, it also pastes the filename, but Paste Special now has (as an additional type):

  • Picture (TIFF)

Which pastes the file’s icon image.

When I try to paste into TextEdit, I do see what others reported - an embedded copy of the media file (clearly, based on the NSFilenamesPboardType data, which has the paths to all the copied files).

I use this app and loved it for years. Last week I finally upgraded my MacBook Pro from High Sierra to Catalina, and Plain Clip bit the dust. I spent a few hours looking for an alternative, and am now a very happy user of PopClip, which has a lot of other word services that have fallen by the wayside in other utilities.

Plain Clip works on Catalina. From the website: “Current version: 2.5.2, released on 10/18/2018. Compatible with macOS 10.7 or higher.” And confirmed by me. I have used it on Catalina until recently. Now active on Big Sur and Monterey on my computers.

1 Like

I think the issue was twofold:

I was on my companion’s computer, not my own; and on my own I have
BBEdit and use it automatically as text editor. She doesn’t have it,
so I tried to use TextEdit as if it were a text editor, and it isn’t
really. It’s more of an everything editor.

and

My version of Excel into which I paste filenames under 10.11 and
10.14 may be older than hers, and hence it may respond differently
when the contents of clipboard (subsqeuent to selecting files and
copying) is pasted.

1 Like

Just today, I tried to copy multiple cells (containing only text in the default font for the workbook) from an Excel workbook and Paste and Match Style, which I assumed would paste the text, into a Pages document. Nothing happened. Repeat, still nothing. I pasted into BBEdit (because of this thread!), cut the text, and pasted into the Pages document with no problem. I was surprised because I would have expected the text to come through the paste operation.

I’m not seeing what looks like the simplest solution here. Open the terminal, use cd to change to the appropriate directory, and use “ls” to list the files, pipe them into a text file:

ls > ~/Documents/list-of-movies

Then import the file list-of-movies that’s in the Documents folder into Excel. Done?

1 Like

I’m sorry but if you think that’s the simplest solution we have a massively different definition of “simplest”.

I don’t typically want a text file, I want the bloody filenames on my clipboard.

I don’t want to have to navigate via terminal to the appropriate directory, I want to click in it, do Command-A, Command-C, then paste the bloody filenames where I want 'em.

Clearly you’re right! :blush: Many blessings to you and yours in this holiday season.

1 Like

TextEdit can be used as a simple text editor by changing its New Document > Fomat Preferences default setting to Plain text instead of Rich text. Hope this helps.

Text Edit (especially as shipped with current versions of macOS) is really a bare-bones word processor. When editing in Rich Text mode (the default for new documents if you don’t change it in Preferences), it supports quite a lot of features they go way beyond a basic text editor.

Agreed, TextEdit is considerably more than a basic text editor. If you need a basic text cruncher, such as here, for pasting file names, you don’t have to change TextEdit’s preferences, so that it always opens in plain text mode. Simply open a new document and choose Format > Make Plain Text (Shift-Command-T).