JavaScript for Automation: getting the clipboard

In AppleScript, it is possible to get the system clipboard with something like the following:

set s to the clipboard as text

If you run this in Script Editor with “clip” on the clipboard, you should see this:

In JavaScript for Automation (JXA), you can achieve the same thing with the following code:

app = Application('System Events');  
app.includeStandardAdditions = true;  
s = app.theClipboard();

You can also use:

app = Application.currentApplication();  
app.includeStandardAdditions = true;  
s = app.theClipboard();

Beginner GIS: spatial querying to find Census Blocks inside urban areas

I know literally nothing about GIS, but I need to figure it out because I need to do some spatial querying. Specifically, I need to find all the Census Blocks that are in a given urban area. This is a  I'm documenting it here for anyone else who needs to get into GIS and doesn't know where to start.

QGIS is the application of choice here. It's like open source ArcGIS. ArcGIS is the Microsoft Office of GIS.

Setup on OS X

You need matplotlib from this page.

Download QGIS (open source ArcGIS). You need the GDAL and NumPy installer from this page as well.

Opening Census shapefiles

I want to work with this shape file from the Census for urban areas (ftp://ftp2.census.gov//geo/tiger/TIGER2010/UA/2010/tl_2010_us_uac10.zip). Download, unzip. The in QGIS go to Layer > Add Layer > Add Vector Layer...

Looks like it works.

Adding another layer

I want to look at Census Blocks in a specific urban area. For example, Abbeville, LA (UACE=00037) as defined here.

Same deal as before for adding the layer (ftp://ftp2.census.gov//geo/tiger/TIGER2010/TABBLOCK/2010/tl_2010_22113_tabblock10.zip). Then do this to see them overlaid:

Finding Census Blocks in the urban area

First, find Abeville using the Query Builder (cmd-f):

This will hide all the other urban areas from the map. Go back in to the Query Builder and delete the query to get everything back.

Select the urban area of interest using the "Select Features" toolbar button (yellow square with a mouse pointer).

Now, to find the blocks in the urban area. This is done with the Spatial Query plugin. Enable it by going in the Plugin Manager in QGIS, searching for "spatial" and toggling the checkbox. You should have this icon in the sidebar now:

Then run this query by clicking that button and selecting the appropriate items in the dropdown (in the screenshot, the results are shown too):

Create a new layer based on the spatial query:

Then right click on that layer created from the spatial query, choose "Save As..." and save it as a CSV. This will export the attribute table for the layer, which is essentially a list of all the Census Blocks in the specified urban area!

Now, on to automating this for all the urban areas in the US.

Full text lookup bookmarklet

I often want to find the full text article for a PubMed entry. This simple bookmarklet takes the PubMed page for a specific article (like this one) and goes directly to the list of full text options for my library. It beats the "Find at UMB" button that PubMed sometimes displays because it doesn't open a new window.

I'm posting this here because it could be easily modified for a different library.

You can use this bookmarklet creator to make your own bookmarklet with the code above.

If you're from UMB and want to use my bookmarklet, go to this page.

LiveReload Using Guard and Rack With No Browser Plugins

I sometimes want to use LiveReload to automatically refresh index.html when I'm working on some JavaScript. Yes, you can use the $10 app, but I generally end up using Guard anyway for compiling CoffeeScript or SCSS, and I dislike browser plugins because of the security risks. Turns out that it's pretty easy to get LiveReload working with Guard and Rack sans plugins.

The code is in a Gist below. All files go in a single folder (say, ~/git/myproject). To run it (after bundle installing), open two Terminal tabs in this folder. In the first one, run guard. In the other, run ruby serve.rb. Then hit up http://localhost:4567 in your browser of choice. LiveReload should automatically reload the page when you change index.html (as configured; modify the Guardfile to watch additional files for changes).

(These instructions are a little vague, because if you can't easily fill in the blanks you should probably just use the app. It's not worth learning all about Ruby/Gems/Rack/Guard to save $10.)

MailMate: my custom keybindings

I'm giving MailMate a try again after using Mail.app for the last six months. I accidentally deleted my custom keybindings 😢 so I had to re-create them. Here's what I came up with, on top of the built-in Gmail keybindings:

Note that some of these are not listed in the official custom keybindings documentation.

So far it's good to be back in MailMate. Mail.app has been getting slower and slower, especially search, which prompted my switch. So far I like the (fairly minor) changes to MailMate since I used it last.