Scratch File - Add to Top

September 27, 2011 by Gabe | [mmd] |

I modified my scratch file script. The new version appends the clipboard to the top of the file rather than the bottom. That way the scratch file is in chronological order.

WARNING: This script overwrites the contents of a file.

[cc lang="AppleScript"]do shell script "pbpaste > '/tmp/qqq_Scratch.txt' echo >> '/tmp/qqq_Scratch.txt' cat '/Volumes/Macintosh HD 2/Dropbox/Notes/qqq_Scratch.txt' >> '/tmp/qqq_Scratch.txt' cat '/tmp/qqq_Scratch.txt' > '/Volumes/Macintosh HD 2/Dropbox/Notes/qqq_Scratch.txt'"[/cc]

Just as a Unix reminder, the double angle bracket ">>" will append text to the end of another file. The single angle bracket ">" will create a new file or overwrite the existing content.

This new version of the script takes advantage of the hidden tmp directory on OSX to first store the contents of the clipboard. It then adds a new line char with the echo and finally writes the previous contents of the scratch file into the temporary file. It then overwrites the scratch file in my notes directory with the contents of the temporary file.