Monthly Archives: September 2011

Antler, North Dakota

Antler, North Dakota, originally uploaded by afiler.

Devils Lake, North Dakota

Devils Lake, North Dakota, originally uploaded by afiler.

Caanan Church Addison, North Dakota

Caanan Church Addison, North Dakota, originally uploaded by afiler.

Davenport, North Dakota

Davenport, North Dakota, originally uploaded by afiler.

Barrie, North Dakota

Barrie, North Dakota, originally uploaded by afiler.

Coburn, North Dakota

Coburn, North Dakota, originally uploaded by afiler.

Alice, North Dakota

Alice, North Dakota, originally uploaded by afiler.

Lightroom Lua Shell

I’ve just written a quick lua shell plugin for Lightroom, mostly to help me write other plugins, but I think it will also be an easy way to manipulate photo metadata. Writing it was pretty easy, though my one frustration was that the Lightroom plugin API does not appear to provide a way to make scrollable dialogs, so the output view will fill up and have to be cleared. The famous Lightroom plugin writer Jeffrey Friedl appears to have solved this by writing his own scrollbar widgets, so I may have to do that eventually.

To get the code/plugin (I’ve left the Lua uncompiled), head to

Pre-loaded extras provided in the shell environment include:

  • catalog => LrApplication.activeCatalog()
  • target => LrApplication.activeCatalog():getTargetPhoto()
  • targets => LrApplication.activeCatalog():getTargetPhotos()

Of course, you can still call import() just as you would inside a plugin.

Note that commands that would normally need to be called asynchronously (within an LrTask) are silently wrapped, so that:
x = target:getRawMetadata(‘fileSize’)
LrTasks.startAsyncTask(function() x = target:getRawMetadata(‘fileSize’)) end)
Note that in the result window, normal return values are prefixed by “->”, while asynchronous return values are prefixed by “=>”.

Sunset, Poland, near the Ukranian border

I found this photo by Panoramio user bajtomir on Google Maps.

Ruby: including class methods as if they were a module

Ruby’s File class has many public class methods named like their shell command counterparts, like chmod, chown, basename, stat, etc. These are very convenient when writing a shell script in Ruby, but typing “File.chown” isn’t as convenient as just “chown”. Now, if File were a module, I could include this module and I’d be done. Many file-related methods are available in the module FileUtil (third-party in Ruby 1.8, standard in Ruby 1.9) as well as FileTest. Methods like basename and stat are available in neither, so I thought a quick solution might be to also include File’s class methods. There doesn’t seem to be any straightforward way to do this, perhaps because File may be one of the few classes with so many static methods that don’t come from a module. So, a quick, dirty, Ruby metaprogramming solution:

def include_class_methods(klass)
  eval <<-EOF
    class << self
      klass = eval('#{}')
      klass.singleton_methods.each do |sym|
        define_method(sym) do |*args|
          klass.send sym, *args

Note: this doesn't seem to work in Ruby 1.9, as File.singleton_methods is empty. One possible replacement for File.singleton_methods is (File.public_methods - File.public_instance_methods - File.ancestors.reject { |x| x == File }.map { |x| x.methods }.flatten). Yeesh.