Is Lightroom plugin development worth learning for automating repetitive catalog tasks?

Asked 4/17/2012

4 views

2 answers

0

I’m using Lightroom 4 and want to automate repetitive library-management tasks, such as:

  • In stacks containing RAW+PSD+JPG versions, find the JPEG in each stack and make it the top image
  • Copy metadata in bulk from existing RAW files to matching existing JPEG files

I’m comfortable with C/C++, Python, and Perl, but I haven’t used Lua before.

How practical is Lightroom plugin development for this kind of workflow automation? Is the SDK approachable for someone new to Lua, and can plugins handle tasks like these? Also, are there any good ways to get started, or would a system-wide automation tool be more suitable for simpler repetitive actions?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

14y ago

2 Answers

40

I've not done anything with Lua

Lua is probably the simplest, cleanest programming language I know. (And I know a few.)

Lua's simplicity is also its biggest weakness: being a small, clean language by design, it doesn't have a lot of stuff built into it that you'd expect to find when coming from an industrial-grade language like Java, or a batteries-included language like Python.

Lua is designed to be extended by C, which in this case means Lightroom's SDK. That's great if Adobe's done the work to provide the tools you need that aren't built into Lua, but every now and then you'll probably find yourself calling out to external tools to get things done.

Is the Lightroom API easy to hook into

The only tricky part about it is that you need to structure your source code in a particular way and provide a special Info.lua file to tell Lightroom about your plugin. It's all explained in the SDK docs. The SDK includes several functioning plugins to start from, including a fairly elaborate "hello world" plugin which can be scavenged for useful starting code.

does it require any specialized tools for development?

You can get by with just a text editor.

There is no debugging facility built into Lightroom, but there is a debug logging facility in the SDK. You can catch these messages in either WinDbg on Windows or Console on OS X.

A more recent development is the open source ZeroBrane Studio Lua IDE. You can use this instead of another text editor, but the really cool bit is that it is possible to attach it to your running plugin which lets you debug it as it runs. I've tried this, and it does help reduce the fix/reload/restart debugging cycle time.

Can I write scripts to perform the kind of tasks I describe above easily?

I don't think either task is 100% do-able using only the Lightroom SDK, but it can do a lot of the work for you.

select the file in each stack with the JPG extension and make it the top of the stack

Here's some vaguely Lua-like code to get you almost all the way there:

for photo in catalog:getMultipleSelectedOrAllPhotos() do
    for peer in photo:stackInFolderMembers() do
        if string.find('%.jpg$', peer:getFormattedMetadata('fileName')) then
            -- *mumble* move 'peer' photo to top of stack *mumble*
            break
        end
    end
end

Unfortunately, I don't see a way in the SDK to do that innermost comment line's action, as of LR 5 at least. The best I can come up with is to call catalog:setSelectedPhotos(peer), then leave it to the user to actually click the number badge to reorder the stack.

Perform a mass copy of metadata from an (existing) RAW file to an (existing) JPEG file

You can do some of this with the existing SDK, but there are limitations.

For example, while you can read the value of the EXIF dateTimeOriginal field, there is no facility in the SDK itself to set the value. I assume this is because the Lightroom developers decided this shouldn't ever be changed programmatically, that it is precious information from the camera. (Why that should be the case when there is a Metadata > Edit Capture Time... menu item I don't know, but there you have it.)

But, whenever the SDK tries to trap you with one of these limitations, there is often an escape hatch. You can install ExifTool and call out to it from Lua, for example. That's not a perfect solution, because you then have an inconsistency between the catalog metadata and the photo metadata, but Lightroom will notice and put a badge on the photo, which when clicked will let you resolve the conflict by reloading the metadata from the photo.

(You'll want to have the "Automatically write changes into XMP" option set in the Catalog Settings dialog when using such a plugin. Otherwise, you make it easier to create a two-way conflict, where both the catalog and photo metadata have changed. Lightroom doesn't know how to merge the two sets of metadata; it makes you pick one, and it overwrites the other metadata copy with it.)

Originally by user4141. Source · Licensed CC BY-SA 4.0

user4141

14y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Lightroom plugin development can be worthwhile if you need catalog-aware automation rather than just replaying UI clicks.

From the answers, Lua itself is relatively easy to learn: it’s a small, clean language. The bigger challenge is working within Lightroom’s SDK and its required plugin structure. Lightroom extends Lua through its API, so what you can do depends on what Adobe exposes; for some gaps, people may need external tools.

For batch catalog operations, plugins appear practical. One answer shows a working pattern using Lightroom APIs such as LrApplication.activeCatalog(), catalog:withWriteAccessDo(...), and async tasks, which suggests batch updates over photos are feasible.

If your automation is mostly repetitive keystrokes or menu actions, a system-wide macro tool like AutoHotKey may be faster to implement than a plugin, since it can automate UI interaction without modifying Lightroom.

So: plugins are worth learning if you want deeper, data-driven automation inside Lightroom; macro tools are often better for simple UI repetition.

A good starting point is the Lightroom SDK documentation and sample plugins, then experimenting with a small batch task like updating metadata or ratings.

UniqueBot

AI

14y ago

Your Answer