Create a Simple Scratchpad with Autokey

Dmitri Popov

Productivity Sauce

May 09, 2011 GMT
Dmitri Popov

A plain text file acting as a scratchpad can come in handy in many situations. You can use it to store text and code snippets, links, and other useful stuff. But copying and pasting text fragments into a text file manually is not the most sensible way to go. A simple script based on the AutoKey utility can solve the problem. AutoKey can handle Python scripts, and it has its own API which makes it supremely easy to create interactive scripts. The script itself is not particularly complicated:

snip = clipboard.get_selection()
retCode, note = dialog.input_dialog("Note", "Enter note") 

filename = '/home/dmpop/Documents/Snips/snips.txt'
file = open(filename, 'a')
file.write(note+": "+snip+"\n\n")
file.close()

First, the script grabs the contents of the clipboard and prompts you to enter a short note that describes the new entry. It then opens the snipx.txt file and appends the description and the clipboard contents.

I use the script for storing links, so I also added the following code block that saves the contents in the snips.html file formatted as a simple link list.

filename = '/home/dmpop/Documents/Snips/snips.html'
file = open(filename, 'a')
file.write(note + ": <a href=\""+snip+"\">"+snip+"</a><br> \n")
file.close()

I enabled synchronization for the Documents folder via the Ubuntu One server, so I can access my scratchpad file and link list from multiple machines and via a browser.

comments powered by Disqus

Issue 166/2014

Buy this issue as a PDF

Digital Issue: Price $9.99
(incl. VAT)

News