There is some sensitive data (credit card numbers and such) that I store on my hard drive, encrypted. I use a script to decrypt the data and display it in the terminal window. When I am finished, I would like the script to clear the terminal, so that the sensitive data can no longer be viewed (even if someone gains access to my computer).
I have read here that ⌘+k clears the terminal output. To implement this in a script, I used AppleScript as suggested in the accepted answer to this question:
/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'
Finally, my script closes the terminal window with
killall Terminal
The problem: if I leave the terminal window with the sensitive output open for about 30 seconds or longer before closing if, then the next time I open terminal, it restores the sensitive data (the text [restored] is displayed below it). If the data was initially displayed for less time, it is not restored.
How can I clear the terminal window from within a script, and prevent Terminal from restoring the cleared data?
I am running OS X 10.10.3.
Best Answer
Final Solution:
Remove the Terminal saved state, located in:
Then, make that folder read-only so that it can't be written to.
You can use the
clear
command to clear your terminal window from within a script. As noted on this other thread, the following commands in sequence will clear the current buffer, then the scroll back buffer:Alternative 1
Turn off Terminal.app's window restore functionality:
Alternative 2
You can also store sensitive information in the
Secure Notes
section within the Keychain Access utility.