Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Clear the terminal screen & scrollback buffer (See related posts)

# make sure access for assistive devices is enabled in the "Universal Access" System Preference
open /System/Library/PreferencePanes/UniversalAccessPref.prefPane

# cf. Terminal -> Scrollback -> Clear Scrollback [cmd-k]
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
}

clear_screen


# you may use clear instead if scrollback is disabled in Terminal.app
defaults read com.apple.Terminal Scrollback
defaults write com.apple.Terminal Scrollback -string NO
#defaults write com.apple.Terminal Scrollback -string YES
kill -HUP $$
[cmd-n]
ls -l
clear

# in addition it may be useful to disable adding commands to the history list
#open -e ~/.bash_history
#set +o history   

You need to create an account or log in to post comments to this site.