Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I see a nicely colored output in my terminal.

The terminal has a "Export Text As" command but it saves a plain-text file without the colors. Same with copy&paste.

Do you know a way to save terminal output including colors?

share|improve this question
If this is important to you, please let Apple know via (Applications/Utilities feedback area) or (requires registering for a free developer account). – Chris Page Mar 10 '12 at 21:42
up vote 5 down vote accepted

It appears that if you select text in the Terminal, then copy it, then paste it into an application that supports rich text (e.g. Mail, TextEdit, Word), then the text color will be preserved.

It appears that in Mail and TextEdit, the background color of the terminal is also pasted; in Word, it is not. I'm not sure how to explain this discrepancy.

share|improve this answer
What version of OS X are you using? This doesn't work on 10.7.4. – Wildcard Mar 18 at 0:45
@Wildcard It works for me on 10.11.3. I don't remember which version I was using when I wrote this – Max Nanasy Mar 18 at 0:48

Amazing how posting a question boosts ones creativity.

I can open "Print" dialog and save to PDF and then copy colored output from the PDF.

Also iTerm2 terminal app has a shortcut CMDOPTC that copies with formatting.

share|improve this answer
This solution is perfect for maintaining colored output when creating terminal examples in a Keynote presentation. Thx! – beausmith Sep 19 '11 at 1:25
@Wojtek: I think you can accept your own answer if you like it best... – martineau Mar 4 '12 at 19:11
@martineau thanks (-: – Wojtek Kruszewski Mar 6 '12 at 9:28
@Wojtek: You're welcome, even though it cost me a little reputation when you unaccepted my answer... ;-) – martineau Mar 6 '12 at 19:36

you can try to paste the colored output to the clipboard like this:

% command_which_produces_colors | pbcopy -prefer rtf

which puts some rtf (possibly colored and formated) stuff into the pasteboard of macos. you can then use any other that understands richtext to access the clipboard.

this is obviously not the same as "select it with the mouse" but maybe worth a shot.

share|improve this answer
Doesn't seme to work. First problem is that command_which_produces_colors notices it doesn't print to the console so it skips the colors. I can force some of them to print colors anyway, so following command outputs colors to the terminal: CLICOLOR=1 CLICOLOR_FORCE=1 ls -alh | tee But pbcopy copies no colors: CLICOLOR=1 CLICOLOR_FORCE=1 ls -alh | pbcopy -prefer rtf +1 for pbcopy/pbpaste commands. It's great for copying long files to clipboard: "pbcopy < longfile.txt" – Wojtek Kruszewski Jan 13 '11 at 7:46
When I try this, if command_which_produces_colors produces ANSI codes, then pbcopy -Prefer rtf just copies the text including the ANSI codes (e.g. it copies [0;34mText for blue Text). It seems as though converting the ANSI codes to RTF may be required as an intermediate step. – Max Nanasy Jan 8 '15 at 2:13

OS X has several keyboard shortcuts (hotkeys) for copying the screen. These will save your screenshots as a jpg files on the desktop. Here's a list of them:

Cmd-Shift-3                             Take snapshot of the whole screen
Cmd-Shift-4                             Take snapshot of the selected area
Cmd-Shift-4-Spacebar                    Take picture of a window
Escape                                  Cancel
Hold Spacebar after Drawing the region  Move the selected area
Hold Option                             Resize selected area
Hold Shift                              Resize selected area horizontally 
                                        or vertically 

There's also a "Grab" application located in the Applications | Utilities folder that does the same job, plus has a few extra features such as delay.


In Snow Leopard (10.6.8) the default screenshot format is png not jpg, although that can be changed to any one of many others -- including pdf -- using the free 3rd-party TinkerTool preference settings utility.

share|improve this answer
a .jpg is kind of not as nice as "pure" text. – akira Jan 4 '11 at 18:23
+1 for the lesser known shortcuts for selection area. – Daniel Beck Jan 4 '11 at 19:05
@akira: The OP wants colors -- something you can't do in a plain-text format unless you count embedded ANSI escape sequences -- and those would need something to interpret them like a terminal emulator, but then you're back to the original problem. – martineau Jan 4 '11 at 21:11
@martineau: depending on the capabilities of the clipboard colors are saved by markup (eg, richtext or html) when you copy from a browser or from word or from xyz. and, depending on the application that receives such marked up snippets they can show the colors AND the text quite ok. the terminal receives ascii escape sequences, correct, but just because it receives ascii escape sequences does not mean it has to a) store them (eg, think html-terminal) b) it can enhance the selected text a lot of ways (you can put different mime-types at a good clipboard at once). – akira Jan 4 '11 at 21:48
@akira A JPG is a really poor choice of image format for something like a screenshot. Large areas of single color and sharp single pixel lines etc. all over it. Fortunately, Apple are not that silly and the file it saves is a PNG. – rjmunro Mar 1 '12 at 11:09

Based on @akira's answer, I came up with the following:

  1. Download the source package for ansifilter
  2. Follow the instructions under INSTALL to build and install ansifilter
  3. Run <command that produces colors> | ansifilter --rtf | pbcopy -Prefer rtf
    • You may need to pass arguments to <command that produces colors> to force it to produce colors even though its output is piped, e.g. ls --color=always instead of just ls
  4. You can then paste into an application that supports rich text (e.g. Mail, TextEdit, Word)
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .