Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Similar to the question How to reset teminal under mac os x, I was wondering how to reset the scrollback buffer of a mac osx terminal window from a script.

I know I can hit Cmd-K to reset it manually, but I often forget to do this before running a script with a lot of output. It would be easier to remove the scrollback buffer at the beginning of my script. The "clear" command doesn't reset the scrollback buffer, so when I scroll up I still see the previous scripts output.

share|improve this question
    
Not sure if it works on Mac OS X (on Linux it does), but try reset. –  cYrus Feb 9 '11 at 18:05
    
reset does not clear the screen or the scrollback buffer on macosx. –  Aaron Feb 9 '11 at 18:35

1 Answer 1

up vote 3 down vote accepted

Clear the terminal screen & scrollback buffer

Make sure access for assistive devices is enabled in the "Universal Access" System Preference

Take 2:

Command-K = Clear Scrollback, and Terminal supports Applescript:

function clear_screen() {
   /usr/bin/open -a Terminal
   /usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'
   return 0
}

This can then be Invoked by running:

clear_screen

Via: http://codesnippets.joyent.com/posts/show/1738

share|improve this answer
    
This only clears the screen in macosx. It does not clear the scrollback buffer. –  Aaron Feb 9 '11 at 18:33
    
I found another method, see my edited answer –  Nathaniel Bannister Feb 9 '11 at 18:48

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.