Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print the contents of an OSX textclipping file from terminal?

Tags:

bash

macos

In OSX (I'm on 10.7.x, Lion), you can grab some text from most any app and drag it to the desktop to get a "snippet.textClipping" file. The file is not just raw text, though -- the text is hidden away, somewhere (in a resource?) I've tried poking around with DeRez, but haven't been able to bend it to my will. What I'm looking for is the ability to get what one might think would be the output from

cat mysnippet.textClipping

NOTE: These clippings were made under an older version of OSX. Maybe Leopard. Maybe older, it's been a while. :)

Thanks!

P.S. I've got a folder with 1600+ of them, that's why I'm looking to script this, not just manually copy/pasting them into a text file.

P.P.S. Yes, if I just select-all then drag into an open, empty text document, it does as you'd expect. But I still want to do it via script, so I can put the name of the clipping first and a blank line ahead of each, etc.

like image 929
Olie Avatar asked Jul 06 '12 20:07

Olie


1 Answers

Here's something ugly that could work:

DeRez -only TEXT foo.textClipping | perl -ne 'm|/\* (.*) \*/| && print $1; END {print "\n"}'

Basically, it extracts the text from the C-style comments in the DeRez output and prints it all on one line. I got the idea from another Stack Overflow question (which I cannot find now).

like image 189
chepner Avatar answered Sep 16 '22 11:09

chepner