Design patterns

(about researchr)

The development of this project was very gradual and iterative, and I added functionality either because I really needed it, or because I had a neat idea and wanted to see if it was possible. During this time, I came across a few “neat ways” of doing things, which I reused a few times. x-bdsk://commons2011power See details of all the files in the repository, and links to the source, at description of all files, and examples of appscript strings.

Using two scripts, and growl, to make a simple menu

I used this in two different scripts, gscholar.rb and imfeelinglucky.rb (now defunct because of the API being deprecated). I first grab whatever is selected, and do a search. I parse the search for results, and display the top results through growl. I simultaneously write the top results to a temporary file.

Keyboard Maestro binds CTRL+CMD+ALT+16 to another script, which accepts a number as input (ie. CTRL+CMD+ALT+1 is bound to imfeelinglucky-y.rb 1). The second script reads in the temporary file, chooses the appropriate option, and performs the action.

Pashua (see below) might offer a more elegant way of doing this.

Pashua and wikipage selector

Pashua is a framework that makes it very easy to generate GUI dialogs on the fly from command line scripts. I use it to generate the wikipage selector, used by dokuwiki-go.rb, dokuwiki-sbs.rb and dokuwiki-clip.rb. I simply iterate over all the files in /wiki/data/pages, and display these in a drop-down box. Because it automatically searches on typing, it makes it very easy to quickly pull up a relevant page. The user can also manually type in the desired name. (I abstracted this function away into utility-functions.rb).

The most recent file

In trying to make the workflow as non-intrusive as possible, I realized that many times all we do is add the most recently downloaded file to a publication, link to the most recent screenshot, etc. Why not automate this? I use the function File.last_added() in utility-functions.rb in

  • skim-screenshots.rb, where it adds the last screenshot to a tmp file, to be parsed and imported when importing the highlights to DokuWiki
  • bibdesk-linkfile.rb, to autolink the most recently downloaded PDF to the currently selected publication
  • dokuwiki-image.rb, imports most recent screenshot to DokuWiki, and outputs a properly formatted link

Creating a new URL schema

I wanted to open PDFs automatically from DokuWiki, and what's more, not just open the PDF (I could presumably just have linked to the file), but also on a specific page. This was inspired by Eboulides, who has a very elaborate workflow which uses DevonThink URLs to open a PDF to a specific page. Skim does not offer a URL schema (see here). However, it's quite easy to create an App wrapper for a tiny Applescript, which runs a ruby file, and in the Info.plist, attaches itself to a certain URL-scheme.

I ended up using this for

  • bibdesk: - opens a given citation in BibDesk
  • skimx: - opens a given PDF in Skim, optionally goes directly to a certain page (for linking notes)
  • ruby: - run any Ruby program, use it for the add author

(You can find these app-files in the github repository, they are easily modifiable for other needs).

Injecting javascript to create side-by-side windows

I have always liked side-by-side editing interfaces, like the one Scrivener offers. I had the idea that I could use some javascript to load two frames, and Dan Diebolt was kind enough to help me out. It started life as a bookmarklet in the browser, then I put it into the page proper. Finally, I use Ruby to inject the javascript into Chrome through AppleScript for the dokuwiki-sbs.rb script (edit any page next to a wikipage, if it's not a wiki page, it gets processed through Instapaper to look cleaner, and work better in a half window). This is now a key part of my workflow, and I really love how flexible it is.

Print/export