OS X: copy/paste filenames
September 24, 2006 8:39 PM   Subscribe

In OS X, if you select a series of files in a folder and paste them into a text editor (say, BBEdit) the order of the filenames seems completely random. Why doesn't it just paste a list of the filenames in the order in which they appear in the folder (or in the order they were selected)? And is there any way to get this result using the Finder (i.e. without going into Terminal and using ls)?
posted by gwint to Computers & Internet (9 answers total) 1 user marked this as a favorite
 
Try Column View. I jsut ran a few tests and it appeared to paste files in the correct (alphabetical) order.
posted by pmbuko at 9:34 PM on September 24, 2006


In Unix, in cases like that, the files are listed in the order that they're linked in the inode chain, which has to do with the order in which they're added to the directory. I don't know if Apple changed that in the process of adapting Next's OS, but I bet it hasn't.
posted by Steven C. Den Beste at 10:29 PM on September 24, 2006 [1 favorite]


I concur with pmbuko. Regular Finder views don't do this but Column mode does. But then of course you only get alpha order.

I don't think you're going to get "order you selected them" ever, but how about, if you're happy with the command line, you at least make it easier for yourself:
ls -t | bbedit
for instance is "list, by time modified, send output to BBEdit" so there's no need for you to cut and paste.

This is assuming you have the free BBEdit command-line tools installed.
posted by AmbroseChapel at 10:40 PM on September 24, 2006


You can also drag directories into an open document in BBEdit and get the entire structure (with subdirectories) pasted in alphabetical order with auto-indenting. Doing so reveals invisible files and package contents, though, so it may not serve your needs.
posted by thinman at 11:40 PM on September 24, 2006


For those that use SubEthaEdit, it has a command line tool, too, eg.:
ls -t | see
(Which I only found out about when trying to solve this very problem...)
posted by jack_mo at 4:45 AM on September 25, 2006


I wouldn't mention this except for the fact that people have already tried to sell you on the command line.
ls -t | pbcopy
Goes straight into the pasteboard for pasting into {editor-without-command-line}-of-your-choice.

Those who play with the commandline often may also wish to note the existence of pbpaste.
posted by edd at 8:51 AM on September 25, 2006


Response by poster: Lots of great tips here, thanks folks. I'm still a bit mystified as to how the order of filenames is generated in List mode (in fact, I seem to recall this same weirdness going all the way back to OS 9), but the Columns mode trick solves my immediate problem.

As for the command line, I couldn't find a switch for ls that did "smart" number ordering like the Finder does (i.e. 1,2,10 instead of 1,10,2)...?
posted by gwint at 10:28 AM on September 25, 2006


gwint, smart ordering of numeric fields is unreasonably difficult, as far as I know. The following sorta works:

ls -B | sed -Ee 's/[0-9]+/-&-/g' | sort -nt - $(for ((i=0;i<20;i++)); do echo +$i; done) | sed -Ee 's/-([0-9]+)-/\1/g'

foox <-should be last
foo1
foo1x0
foo1xx
foo2
foo10
posted by ryanrs at 11:27 PM on September 25, 2006


>I couldn't find a switch for ls that did "smart" number ordering like the Finder does

Again, not what you want but for the record, BBEdit does that if you tick "numbers sort by value" in the dialog.
posted by AmbroseChapel at 1:44 AM on September 27, 2006


« Older Two different sets of speakers on amp/receiver.   |   "Life is a combination of magic and pasta." Newer »
This thread is closed to new comments.