1

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.

2
  • 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

3

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

2
  • 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

You must log in to answer this question.

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