My primary method of collecting research information while browsing the Internet on my Mac is to clip them as rich text or save links and URLs to Evernote.
There are times however, when I just want a quick way to copy and paste whatever information I select as pure text into a simple text file. In this instance, the text file acts as one big, giant clipboard (let’s call it “Clipboard.txt”) that gets a constant stream of new text incrementally added to the top, a collection point for my rapid-fire copy and paste activity in the browser.
I’d also want to perform this copy-and-paste activity without having to constantly switch between the browser (say, Safari) and the text editor. My text editor of choice for this kind of work is nvALT (a brilliant, Markdown-enhanced fork of Notational Velocity), which is able to instantaneously display the updated contents of Clipboard.txt, and syncs with Simplenote to boot.
It turns out that a free solution exists on the Mac, in the form of Automator, for exactly this kind of requirement.
Please note that if you want to view the generated Clipboard.txt text file in nvALT, the nvALT note storage option `Store and read notes on disk as:` must be set as `Plain Text Files`.
The following are the 7 steps required to construct such a solution, which we’ll name “Send text to nvALT“.
Steps to construct the “Send text to nvALT” Automator service
Step 1 – Launch the Automator app. I prefer to just invoke Spotlight with command+spacebar, type the first few characters of the app’s name, and hit return after the app is selected from the list.
Step 2 – Choose the Service document type. We’re building a workflow that can be called in any application with a keyboard shortcut or selected in a contextual menu brought up with a right mouse click, so select the Service icon and click the Choose button.
Step 3 – Add the Run Shell Script action. Make sure Actions is selected (this is the default), then search for “shell”. Alternatively, click on “Utilities” in the Library column, then click on the “Run Shell Script” action and drag it to the workflow area.
Step 4 – Paste the following code in the Run Shell Script action. I’ll explain in a bit about the script and file choices. Please replace with your own preferred folder and files.
cat > ~/My\ Stuff/@NV/dlc_temp.txt
printf "\n" >> ~/My\ Stuff/@NV/dlc_temp.txt
cat ~/My\ Stuff/@NV/Clipboard.txt >> ~/My\ Stuff/@NV/dlc_temp.txt
mv ~/My\ Stuff/@NV/dlc_temp.txt ~/My\ Stuff/@NV/Clipboard.txt
More details:
- Folder: (User Home)/My Stuff/@NV. Notice in the code that “My Stuff” is entered as “
My\ Stuff“. The script that runs in the shell expects literal spaces to be escaped with the backslash (“\”) character. - Temporary file: dlc_temp.txt. This file is required because I want the most recently-pasted item to appear at the top of my clipboard file. The UNIX shell command
catthat’s used in the code is only able to append (or add) information to the end of an existing file. So I’ll be using “dlc_temp.txt” to paste in the most recent item, followed by a line feed, then the entire contents of the existing “Clipboard.txt”. The script will then rename “dlc_temp.txt” to “Clipboard.txt” and replace the old “Clipboard.txt”. - Clipboard file: Clipboard.txt. This will be the name of the main file that stores all my clipped textual information. Although not necessary, I’ll keep this file open in nvALT so that I can take random peeks at the information that’s been copied so far.
Step 5. Save the service and give it a name. Use command+s or File > Save…. I’m going to call it “Send text to nvALT”.
Step 6. Assign a keyboard shortcut. With a keyboard shortcut, all I’d need to do to add new information is to select some text in the browser (or in any other application for that matter – could also be a PDF in Preview) and hit the shortcut. Go to System Preferences > Keyboard > Keyboard Shortcuts (I usually just search for “keyboard” in Spotlight).
Click on “Services” in the left column, then scroll the list on the right until you see the service you’ve just created. Double-click the empty space just to the right of the service name, and press the keys for the desired keyboard shortcut. In my case, it’s control+command+v.
There are two issues to look out for in this step:
- Ensure that the assigned keyboard shortcut does not clash with any existing combination that’s in use by other applications. In my case,
control+command+vclashes with the “Paste to Evernote” shortcut, so I disabled its use in Evernote. - It might be a bug, but I noticed that whenever I assign a keyboard shortcut in this window, the check mark on the left hand side of the service would disappear, effectively disabling the service. Make sure you check the box, if required, after you assign the shortcut.
Step 7. Use the new service. Open up a web page in your favorite browser or a PDF document in Preview.
Select some text. Clip the text to the text file using one of the following:
Right mouse click > Services (this step is sometimes unnecessary, depending on the application) > Send text to nvALT, or…Name of app in the menu bar > Services > Send text to nvALT, or…- Simply hit
control+command+v. Repeat this as many times as desired.
Open your Clipboard.txt text file in nvALT, a text editor such as TextMate, or in Quick Look (accessed by pressing Spacebar once Clipboard.txt is selected, this window remains open in Mac OS X Lion even after you’ve switched to another app). If you’re on Lion, do not view Clipboard.txt in TextEdit as the displayed content doesn’t get automatically refreshed with the addition of new content.
Summary
It’s pretty easy to build a custom Automator service to incrementally copy new information to the top of a text file. With a keyboard shortcut assigned to perform the copy, paste and file update in one stroke, you’ll save yourself from having to perform lots of tedious and repetitive keystrokes in clipping large amounts of textual information into a text file.








{ 1 comment… read it below or add one }
This is a tremendous tutorial. It works perfectly with my workflow. Thanks very much.