0%

Auto Import Image from SD card to Lightroom

1. Why

I have multiple cameras, and I always shoot with Raw+JPG, but at the end of the day, I only need the raw file since it’s better for post-processing

So everytime I do the work

  1. Open the folder
  2. Select the JPG image
  3. Delete the JPG image
  4. Right click the remained RAW file
  5. Import to Lightroom

This process is simple but I don’t like repeat it, so an automation tool would be great

2. How

In a nutshell, we can use Automator and Python to finish the job

  • Automator is just to run the Python script and tell the Python script where is the location
  • In Python, the code will run the logic 2/3/4/5

image-20230201211240945

Python code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
## Automate the image import process
import os
import subprocess
import sys

## Get the path to the folder containing the images
root_path=sys.argv[1]

## Define the extensions of the raw and jpg files
raw_extensions = [".DND", ".RW2", ".NEF", ".ORF"]
jpg_extensions = [".JPG",'.JPEG']

## Find the raw files and the jpg files
raw_list = []
jpg_list = []
jpg_remove_list = []
for rext in raw_extensions:
for root, dirs, files in os.walk(root_path):
for file in files:
if file.endswith(rext):
raw_list.append(file[:-len(rext)])
print(raw_list)

for jext in jpg_extensions:
for root, dirs, files in os.walk(root_path):
for file in files:
if file.endswith(jext):
jpg_list.append(file[:-len(jext)])
print(jpg_list)


## Find the jpg files that have a corresponding raw file
for jpg in jpg_list:
if jpg in raw_list:
jpg_remove_list.append(jpg)

## Delete the jpg files that have a corresponding raw file
print(jpg_remove_list)
for jext in jpg_extensions:
for root, dirs, files in os.walk(root_path):
for file in files:
if file.endswith(jext) and file[:-len(jext)] in jpg_remove_list:
os.remove(os.path.join(root,file))
# print(f'removing {os.path.join(root,file)}')

## Open the remaining raw and jpg files in default application
command_list = ['open']
for root, dirs, files in os.walk(root_path):
for file in files:
if not file.startswith('.'):
command_list.append(os.path.join(root,file))
print(command_list)
subprocess.run(command_list)