Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

!! | pbcopy would also run the commands again and couldn't be used with interactive commands.

This relies on the prompt always being $ :

tell application "Terminal" to tell window 1 to history
do shell script "/bin/echo " & quoted form of result & ¬
    " | ruby -e 'puts $<.read.split(/^\\$ .*?$/)[-2][1..-1]'"
set the clipboard to result

Does anyone know any better options?

share|improve this question
And !! not good for command with side effects – Rich Homolka Nov 21 '11 at 0:41
Can you add a real example of what you're trying to accomplish with this? Fill in the blanks "I want to copy the output of the last command, because the last command was ________ and I want to paste it into _______" – Doug Harris Nov 21 '11 at 18:40
@DougHarris I'd just want to assign a keyboard shortcut to a general purpose script for copying the previous output. That fill in the blanks thing is insanely patronizing BTW. – user495470 Nov 21 '11 at 19:36
You might consider it patronising, but it's often the best way to succinctly understand what a user wants. – Chris Down Nov 22 '11 at 16:23
You could make exec script $( date +%Y%m%d-%H%M%S ) your Terminal startup command to log everything to a dated log file. One unfortunate side effect is that script is a lousy shell (e.g. always 80 wide) in my limited testing. – Daniel Beck Nov 28 '11 at 20:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.