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?

  • \$\begingroup\$ 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. \$\endgroup\$ Apr 17, 2012 at 19:29
  • \$\begingroup\$ 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. \$\endgroup\$
    – David
    Apr 17, 2012 at 21:35
  • \$\begingroup\$ 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). \$\endgroup\$ Apr 17, 2012 at 22:06
  • \$\begingroup\$ 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 archive.msdn.microsoft.com/changexifwithcsharp and stackoverflow.com/questions/58649/… and stackoverflow.com/questions/226973/how-to-edit-exif-data-in-net. You mentioned that you know C++, I believe you can get yourself into C# \$\endgroup\$
    – K''
    Apr 18, 2012 at 15:29
  • \$\begingroup\$ +1, since this question gave me the idea to look at this Lua sdk :-) \$\endgroup\$
    – Francesco
    Apr 27, 2012 at 19:31

3 Answers 3


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

  • \$\begingroup\$ 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. \$\endgroup\$ Jun 6, 2012 at 7:04
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Jun 6, 2012 at 7:39
  • 1
    \$\begingroup\$ Nice answer - +1. \$\endgroup\$
    – D. Lambert
    Jun 25, 2012 at 21:13

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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – Francesco
    Apr 26, 2012 at 10:55
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Joe
    Apr 27, 2012 at 18:50
  • \$\begingroup\$ 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). \$\endgroup\$
    – Francesco
    Apr 27, 2012 at 19:28
  • \$\begingroup\$ 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. \$\endgroup\$
    – David
    Apr 27, 2012 at 20:52

I just wanted to look at how to do batch processing based on filenames in Lightroom, and for some reason it looked it like the easiest way to do it was through the API. Based on @Warren's post I managed to create this inner loop for a button on a form, where I could also put a textfield for logging (logs_field), and some input values (like a textfield to include the filenames filenames_field and some additional parameters for the batch processing in rating_field):

f:push_button {
      title = "Update",
      action = function()
        import "LrTasks".startAsyncTask( function()
          logs_field.value = "Starting search\n"

          local catalog = import "LrApplication".activeCatalog()
          catalog:withWriteAccessDo("Batch set rating", function( context )
            for i,photo in ipairs(catalog:getAllPhotos()) do
              for fname in string.gmatch(filenames_field.value, "%w+") do
                if string.find(photo:getFormattedMetadata('fileName'), fname) then
                  logs_field.value = logs_field.value .. "Found filename: " .. fname .. "\n"
                  photo:setRawMetadata('label', rating_field.value)
                  photo:setRawMetadata('colorNameForLabel', rating_field.value)
          logs_field.value = logs_field.value .. "Done...\n"

This snippet would go through some filename patterns, and apply a label to all of the photos (you might want to replace getAllPhotos with getMultipleSelectedOrAllPhotos in case you only need to run it on some of your pictures) that match those patterns. I had to do this as I had already tagged the photos outside of Lightroom but needed an easy way to move those tags into LR as well based on filenames.

I put up the whole project as well on github, but the above snippet should be fine to use as a base for filename based batch processing tasks.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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