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.

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

1 Answer 1


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:


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

  • This only clears the screen in macosx. It does not clear the scrollback buffer.
    – Aaron
    Feb 9, 2011 at 18:33
  • I found another method, see my edited answer Feb 9, 2011 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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