Before the rush

Before the rush
by evan-pak

Submit your Photo
Hall of Fame

Please participate in Meta
and help us grow.

Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently upgraded my photo organization and management workflow from "nothing at all" to Lightroom 4, and while I'm generally very pleased with the software, one feature that it's sorely lacking is the ability to record any sort of macros or scripts to automate repetitive tasks -- during the course of my migration into lightroom, there have been a lot of repetitive tasks that I've wanted to do, and I'm wondering if it's worth learning how to write LR plugins to do some of these tasks. To give you examples of the kinds of things that I want to automate:

  • In a large group of stacked RAW+PSD+JPG photos, select the file in each stack with the JPG extension and make it the top of the stack
  • Perform a mass copy of metadata from an (existing) RAW file to an (existing) JPEG file

I can see a lot of other ways that scripts could make image management within Lightroom even easier than it is now. My question then has three parts:

1) How difficult is it to write Lightroom plugins? I'm well-versed in a number of programming languages (C/C++, Python, Perl), but I've not done anything with Lua. Is the Lightroom API easy to hook into, and does it require any specialized tools for development?

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

3) Are there any good resources or tutorials that I can read to get started with Lightroom plugin development?

share|improve this question
I can't weigh in on plugin development--haven't really looked into it--but it sounds like your uses are most specifically for somebody going from no workflow to Lightroom. That is, once you start using LR, you'll never have a need to copy meta from a RAW to .jpg or .psd, for example because that's what the workflow is all about. – Dan Wolfgang Apr 17 '12 at 19:29
That's true, the examples I give I (theoretically) will never need to do again once I'm done with my initial import. However, maybe it's the case that there are other tasks I'd like to be able to automate in the future? I'm not sure on this count. But if it's easy enough to develop plugins, then learning now won't hurt me, and could be beneficial in the future. If plugin development is complex, then I don't want to bother, and will trust that Lightroom will do most of what I need once my library is built. – David Apr 17 '12 at 21:35
Oh, yes, the automation and connectivity options are infinite. I was just pointing it out because, depending upon the size of your library, it may not be worth the effort (at least, for me it wasn't). – Dan Wolfgang Apr 17 '12 at 22:06
while I don't know a way to do this using Lightroom, you can actually build a program to change the EXIF data for all your photos. Please check and… and You mentioned that you know C++, I believe you can get yourself into C# – akram Apr 18 '12 at 15:29
+1, since this question gave me the idea to look at this Lua sdk :-) – Francesco Apr 27 '12 at 19:31
up vote 27 down vote accepted

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*

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.)

share|improve this answer
Fabulous answer! Thanks a lot! – David Jun 5 '12 at 12:30
The limitations of the SDK are actually substantial, the only actions that are officially supported, as per this guide are are adding export or publish destinations, applying additional post-processing on export, or adding custom metadata fields. Any action that requires updating any setting/value is, as the answer describes, likely supported right up until you try and set the updated value. – Steven Cunningham Jun 6 '12 at 7:04
@StevenCunningham: That guide is a tutorial document; it is not meant to comprehensively list all of the things you can do with the SDK. In addition to that programmer's guide, the SDK also includes an HTML reference. There are quite a few things Adobe has documented in that reference that they didn't cover in the PDF programmer's guide you point to. See the LrPhoto:setRawMetadata() section, for example. – Warren Young Jun 6 '12 at 7:39
Nice answer - +1. – D. Lambert Jun 25 '12 at 21:13
@PaulKulchenko: I finally had the opportunity to try ZeroBrane Studio to debug an LR plugin recently, and it truly is an advance over debug logging. Thanks for the tip! – Warren Young Dec 7 '14 at 3:48

I don't know Lightroom (yet - have it but haven't installed it yet), but depending on the complexity of what you're trying to do, you might want to look at a system wide keyboard macro/automation tool like AutoHotKey. It lets you record or program any sequence of keystrokes that you can figure out and then, when you press a hot key, it plays them back into your program (such as LightRoom) so that - as far as the program is concerned - it looks like you typed it. This allows you to automate all sorts of things without having to modify your application programs at all.

share|improve this answer
Surely a plugin will offer more fine grained automation solution, this is a sort of extreme ratio and OS-dependent. I assume plugins are (more or less) portable between Windows and OSX. – Francesco Apr 26 '12 at 10:55
@Francesco - I'm sure you're right, but you probably need a lot more programming skills and a knowledge of the LightRoom API (or whatever they call the interface for macro writers) to go that route. Although a fair number of people do multiboot or use vms, most people probably stick to one OS and there are similar macro processors for Linux, Windows, and OSX. The hard part is getting the sequence of actions right. For most simple things, recoding from one macro processor to another is not very difficult. – Joe Apr 27 '12 at 18:50
I see your point but in my opinion it's a bit out of scope given the original question (OP is well versed in a series of languages, just not Lua). In any case I didn't think that your answer deserves to be downvoted since it provides a possible solution to the problem at hand (it is a sort of think-out-of-the-box approach, I'd say). – Francesco Apr 27 '12 at 19:28
This is certainly a valid option, and something I've thought about a little bit. I think I would prefer a Lightroom-specific approach, which seems to have better longevity -- I anticipate that the Lightroom API will change less from version to version than an OS-dependent macro solution. – David Apr 27 '12 at 20:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.