Lightroom Cropping via Keyboard

I'm trying to improve keyboard support for cropping images in Lightroom Classic.

Currently, in crop mode the only way to move the top/bottom/left/right edges of the crop in and out is by click-dragging with the mouse - I'd basically like to setup key shortcuts to nudge the edges and avoid using the mouse altogether.

The difficulty is locating the crop edges or crop handles, as while image searching for the handles onscreen would theoretically work, the graphics are too small for KM to reliably recognise (and as they overlay image content, parts of the square handle graphic would vary - I tried setting this area to transparent in the image to search for, but no joy on that front either.)

As I move the mouse over the edges of the crop, the mouse cursor changes - I'm not sure offhand whether the mouse cursor is still recognised as being on the screen image, or not (I will try and verify) but even so, it's starting to get hacky to guess the image edge position and move the mouse until the cursor changes - or require me to first position the cursor on the edge to be moved.

Anyone done anything similar, or has any tips?

Once I've located the mouse position, the nudging part is fairly trivial, it's just a small automated click and drag in the desired direction. I just need to be able to reliably locate the corner handles on screen...

Thanks if anyone has any ideas!

I think this is the best you’re going to get with this approach. Assuming you are saying that once you manually position the mouse pointer you can fine-tune the drag using KM and keystrokes? That’s still quite an achievement.

Hi - thanks. Yep, I tried hard but couldn't find a way to programatically determine the crop edges or crop handles.

As I regularly have to go through hundreds of images, tweaking the top/bottom/left/right crops, and rotation, and shifting the image within the crop, a complete keyboard solution would have been preferable.

As it is, Lightroom has key commands for shifting the image within the crop, and rotation (although there are some mode peculiarities which complicate this), I've set up a range of macros to reliably shift up/down/left/right, rotate left/right, nudge the edges up/down/left/right, and move between images while staying in crop mode. (All these are triggered from a MIDI controller with one-key presses).

I put the mouse cursor over the edge to tweak, and then use a nudge macro which uses a small drag to nudge the edge by 1 px in a given direction - this requires less cognitive load and repetitive mouse effort than moving the edges with the mouse manually.

It's not ideal (for example, if you need to nudge both left and right edges you need to move the mouse from either side of the image), but it's better than nothing. And with considered workflows there are ways of minimising the time/effort.

It would be great to not have to need to put the mouse over the edges though - if anyone can come up with a neat solution for that, I'd love to hear it, as it's eluded me so far...!

Firstly the graphics are not "too small" for KM to deal with reliably and the real difficulty is creating the images of the crop handles so that KM can recognise them.

I saw your post and took on the challenge and now have a working macro that reliably detects the crop handles and clicks on them.

Let's tackle the hard bit first: images of the crop handles.

Here's a screen grab of the bottom crop handle on my system:
KM 0 Handle Bottom Uncropped

It shows all the difficulties you mention - specifically (since this is at the bottom) it includes part of the photo being worked on - the blue bits. Obviously, for another photo, this would appear very different hence your belief that KM can't find it in general.

Well, here's the bottom crop handle that I ask KM to search for:

KM 1 Handle Bottom Cropped

As you can see, I've very carefully cropped the image so as to exclude all of the photo that's being worked on in Lightroom. You have to repeat this process for each of the crop handles. It isn't difficult - it took me maybe 10 minutes - but you have to be very precise to ensure that the end result excludes all parts of the photo. By the way, the tool I use to do my screen captures and subsequent editing for KM is Snagit.

To give you an idea of where this bottom crop handle image came from, here is a (resized) screen capture of the develop area in Lightroom with the relevant area shown:

KM 2 Crop Screen

You can barely see any of the crop handles but I just wanted to show you that it doesn't actually matter what the photo that you're working on looks like as long as you get the images for KM right.

Once you've got those four images of the crop handles you can slot them into a KM macro. I've written a demo macro for you to examine. I wrote it mainly as a proof of concept which means that it won't necessarily fit your use case but it contains all the elements you'll need to build a macro of your own.

What it does is this:

  • it only works when Lightroom Classic is at the front
  • you trigger it with one of the arrow keys: up, down, left, right to indicate you want to select the top, bottom, left, right crop handle
  • for each of those crop handles the macro looks for the corresponding crop handle image and then moves the mouse and clicks just a few pixels off-centre where the actual crop handle is (something you'll have to fine tune by trial and error) in order to activate it

Here is a zip file contains the four images of the crop handles that I used:
Crop Handle (14.3 KB)

And now the demo macro:
Test Lightroom Crop Handle Detection.kmmacros (139 KB)

Click to see macro

I've put comments in the macro to help you better understand what's going on but there are a couple of points you need to note:

  1. I made the crop handle images on a non-retina, 27-inch iMac screen, so you'll most likely have to re-make them on your own Mac.
  2. Since I created the macro really just to test things, there's a lot in there you won't need or even find useful.
  3. The main section of interest for you will be the 4-way Switch action embedded in the Try-Catch action which is where most of the hard work happens.
  4. Since the mouse is moved to the found crop handle image, you need to arrange for the click to happen on or very near the actual handle and so the click has to be offset by a few pixels; the actual value of the offset is something you have to determine by trial and error.

There's quite a lot to digest in this post so if you have other questions feel free to ask.

1 Like

Thanks for the post. I did indeed try to make various versions of lines and crop handles, including without any of the source image pixels but couldn't make KM detect them reliably at all. (I was mainly working on the corner crop handles as being more distinctive, but with more of a problem with the source image or course, but I did try some easier edge handles too.)

I'll go through your post carefully and have a look at what you did - thanks for taking the time to look at this!

1 Like

In my testing I tried out my demo macro while in crop mode for 10 different photos - some monochrome but most colour and it detected the crop handles every time. So I guess there must be something you missed.

How did you handle reliably recognising the crop handle in the following situation:- if the crop is right at the edge of the image, the surrounding background is dark grey. Should be easy enough to recognise, as per your example. That's the simplest case.

However, if the crop area is moved into the image (which for me, 95% of the time it is), the surrounding outer crop area is different, it's not dark grey, but is the original image but slightly dimmer. There's only a few pixels on the line you can search for without including any of the source image - hence why I was finding KM not reliably able to find enough graphics to get to the crop handles reliably...

I can't search for just the small crop handle rectangle, as these are not unique so I wouldn't know which one KM found, and I can't include the line and crop handle and background, because of the source image behind it.

(I haven't examined your macro yet, I'm just re-looking at the problem on my end...)

Edit: Ok, it looks like you're assuming the image is always starting in an uncropped state, and I need to only crop in - therefore you're assuming the background is the LR background colour outside the image borders and are image searching based on this.

This means your solution would only work to move a handle inwards the first time. I need to be able to target a handle wherever it currently is, and nudge it left/right or up/down accordingly. I don't think your macro allows this, if I'm understanding your image searches correctly...

1 Like

Busted! You're right - if the image has not yet been cropped, my demo macro works fine. But if you're working on an image that's already been cropped or in the process of being cropped, my macro doesn't cope with that. And examining the crop handles when they're within the photo, there's no way to isolate them from the background. I hadn't tested that. So I guess it's back to the drawing board.

One other idea I've had is this: I've noticed that Lightroom Classic has AppleScript support built in to it so there may be a way of achieving something via that.

The only other thing I can think of to try is searching for the (tiny) vertical handles and try to get KM to reliably recognise just the pair of them, and see if they are always recognised in the same order. Then it might be possible to reliably get to either position (or differentiate by searching within different screen areas). (I think I tried this without success, but I'll give it another go just in case.)

But as the crop handles are small and reasonably generic, the idea I can reliably recognise only them might be too difficult. I'll give it a try anyway and see what I can do...

Edit: Yes, as stated in the first post, the handle on it's own seems to small for KM to reliably recognise. I can save the small grey rectangle crop handle, with it's extra pixel line on each side for uniqueness, like this:

Screenshot 2022-08-25 at 17.03.03


...but KM cannot detect this in the screen, as per my previous tests. It just never finds them, until I fuzz out so much it starts selecting other areas of the screen at random. I'll keep trying in case I'm doing something silly...

(Colour profiles? monitor scaling? Could it be monitor scaling that's causing this... no, doesn't seem to be a problem, as other images on this monitor can be recognised by KM just fine). It seems that possibly the crop handles are below the threshold KM considers is enough for image matching, maybe, and thus it will never work? I can never get KM to recognise this handle image onscreen at all.

Unless it's changed, AS support is limited to the application basics and includes nothing for Lightroom's functionality.

IIRC, Lightroom can use an external editor? How's the round-trip functionality on that? Could you, perhaps, drop out to Graphic Convertor (very scriptable) and do the macroed crop there and then go back to Lightroom?

You can probably tell I've never used Lightroom before -- that might be a very daft idea!

No, that's not an option. After some overall batch cropping and other processes, I have to quickly move through hundreds of images in one session, finely adjusting the batch crops and rotation by eye where necessary (I'm processing image scans).

LR is great for these tasks, and it should take maybe one or two seconds to tweak each image if needed. Round-tripping is completely out of the question, and I use LR for it's non-destructive workflow in general, which is amazing. I'm just trying to make workflow gains on any pain points I find along the way, as when you're working on hundreds of thousands of images over time, any workflow gains become significant!

Have you tried without the extra line of pixels on the left (in your example)? The "inside" black line and the handle itself are consistent, but the "outside" edge of the handle varies dependent on the image pixels "below" it.

That may be enough to make the image unique -- I'm looking at the LR interface over a remote connection at the moment, so I'm afraid I'm not able to test.

Life would be a lot easier if they let you zoom while in Crop mode...


Good spot! Yes, screen zooming in you can see that line change colour as you change position. I hadn't noticed that. I stripped it, and I can now find the handle - which is great progress! :grinning:

Let me fine tune this and play with it and see where we are in terms of reliability... It's very fiddly due to the fairly generic pixel content.

Thanks for the suggestion!

You might, after finding your handles, change to Lights Out mode (a couple of presses of the 'L' key) to get a black background. The handles disappear but the Crop tool is still active.

Yep, I'm aware of that and had explored it. I generally don't want to be in the mode, I like to see the crop and lights out obscures black edges, which is something I need to see to tune out. I don't think I win anything by being in that mode - the problem is really reliably identifying the handles - from there, I'm good and can do what I need to do.

I'm find the handle recognition to be really fiddly though, but restricting the search area will probably help, so that's next to check out...

Thanks for the suggestion. I'm not sure how that helps though!

1 Like

I was thinking of this: "And examining the crop handles when they're within the photo, there's no way to isolate them from the background."

But you're right. you won't find them in Lights Out mode within the photo, although they're still active. They disappear.

1 Like

I think this is going to work! I'm implementing it now, and then I'll fine tune and test on real world workflows, but it looks promising! I can forsee the odd thing cropping up (heh!) like incorrectly matching pixels inside the image, but I can limit checks to screen areas to minimise those things in the course of tuning the behaviour.

Edit: Ok, it's working well so far. I can nudge each border in and out, rotate the image, shift the image in all directions, and step through to the next image staying in crop mode - so basically all the core workflow cropping features are now under single keypress control, without touching the mouse. I'm sure there are ways to fine tune, but I'm super happy so far and this is going to make a measurable difference in my manual cropping workflow.

Thanks so much for the extra brains on this, and of course to @Nige_S for the extra clue!

Follow up: I cranked through a real workload of 150 images earlier, and it's basically working really well. It's not super-fast, I don't know if the drag speed can be improved (edit: just found SetActionDelay which speeds up the drag nicely), but generally it is way less physical effort, and less cognitive load to drive this from the keyboard (especially as I start to build my muscle memory), so it was well worth doing...


@beely that’s a great result! Would it be possible to share your macro? I’m a wedding photographer and similarly have to go through hundreds of images so this could be really useful. Thanks,

Hi Jeff. For me these kinds of very specific personal workflow macros are a "minimum viable product" thing, so the way I have implemented them for my needs isn't necessarily the best way to write/package them as something more general for other people to use (who would likely have to change them for their use anyway, and their monitor setups etc). And there are other tweaks I'd implement for a more general solution and cleaner macro. How I've implemented this for my scanned documents workflow might not make sense for a more general creative photographic cropping situation as well.

The principle though is easy enough - click and drag on the desired crop handle in the intended direction by a certain amount.

I have individual macros, two for each edge (left, right, top and bottom) to nudge them in either direction (ie, the left and right edges can each be nudged left or right, and the top and bottom can each be nudged up and down).

Here's an example of what one of them currently looks like (this is dragging the left crop handle left (ie outwards) by 2px:

Screenshot 2022-08-28 at 10.29.51

I'm restricting the search area to look for each crop handle based on my screen to improve the stability of finding them, and then restoring the mouse position back to where it was before the macro runs so the mouse isn't moving all over the place.

As mentioned, this could be cleaned up (eg combining the click and drag steps into one step and losing the manual mouse restore but there are other reasons why I set them up this way). You could reduce this to a single step, letting KM restore the mouse position, eg:

Screenshot 2022-08-28 at 10.37.29

The rest are existing key commands LR already supports with a few tweaks - to move the image in all four directions, rotate left and right, and move to the prev/next image while staying in crop mode.

Hope that helps!

1 Like