Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active December 22, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dergachev/6541450 to your computer and use it in GitHub Desktop.
Save dergachev/6541450 to your computer and use it in GitHub Desktop.
WeddingPhotoPicks: instructions for exporting a subset of photos from Lightroom

Here are the instructions to filter out just the photos we picked.

I'm attaching a file alex_suzanne_picks.lrsmcol that defines a LightRoom Smart Collection Settings that filters out just the photos we want. This file is identical to the following, but includes all the photos:

s = {
  id = "D7B14054-AE5E-4FC8-8E16-FC0EAA9B9581",
  internalName = "Alex_Suzanne_Picks,
  title = "Alex_Suzanne_Picks",
  type = "LibrarySmartCollection",
  value = {
    {
      criteria = "filename",
      operation = "any",
      value = "DSC-6466.jpg",
      value2 = "",
    },
    {
      criteria = "filename",
      operation = "any",
      value = "DSC-6467.jpg",
      value2 = "",
    },
    combine = "intersect",
  },
  version = 0,
}

This file hardcodes file names like DSC-6467.jpg, so before importing it into LightRoom, you'll probably need to open it in TextEdit and do a find and replace to fix the file name pattern to one LightRoom recognizes (e.g. change DSC-6467.jpg to DSC-6467.CR2).

Afterwards, go to Lightroom, right click on "Smart Collections" and select "Import Lightroom Smart Collection Settings". When the new smart collection Alex_Suzanne_Picks is created, right click on it and select "Export this collection as Catalog".

Here's a screencast, in case it helps:

# usage: ruby make-smartcollection.rb > alex_suzanne_picks.lrsmcol
require 'erb'
@filenames = DATA.read.split("\n")
@template = <<EOT
s = {
id = "D7B14054-AE5E-4FC8-8E16-FC0EAA9B9581",
internalName = "Alex_Suzanne_Picks",
title = "Alex_Suzanne_Picks",
type = "LibrarySmartCollection",
value = {<% @filenames.each do |filename| %>
{
criteria = "filename",
operation = "any",
value = "<%= filename %>",
value2 = "",
},<% end %>
combine = "union",
},
version = 0,
}
EOT
puts ERB.new(@template).result
__END__
DSC-5565.jpg
DSC-5580.jpg
DSC-5584.jpg
DSC-5585.jpg
DSC-5586.jpg
DSC-5588.jpg
DSC-5591.jpg
DSC-5598.jpg
DSC-5604.jpg
DSC-5605.jpg
DSC-5611.jpg
DSC-5613.jpg
DSC-5625.jpg
DSC-5633.jpg
DSC-5637.jpg
DSC-5638.jpg
DSC-5639.jpg
DSC-5640.jpg
DSC-5643.jpg
DSC-5646.jpg
DSC-5650.jpg
DSC-5653.jpg
DSC-5657.jpg
DSC-5661.jpg
DSC-5665.jpg
DSC-5670.jpg
DSC-5671.jpg
DSC-5673.jpg
DSC-5675.jpg
DSC-5676.jpg
DSC-5679.jpg
DSC-5684.jpg
DSC-5686.jpg
DSC-5687.jpg
DSC-5689.jpg
DSC-5695.jpg
DSC-5697.jpg
DSC-5699.jpg
DSC-5703.jpg
DSC-5707.jpg
DSC-5710.jpg
DSC-5716.jpg
DSC-5718.jpg
DSC-5721.jpg
DSC-5728.jpg
DSC-5733.jpg
DSC-5738.jpg
DSC-5739.jpg
DSC-5741.jpg
DSC-5742.jpg
DSC-5743.jpg
DSC-5745.jpg
DSC-5747.jpg
DSC-5748.jpg
DSC-5749.jpg
DSC-5750.jpg
DSC-5757.jpg
DSC-5762.jpg
DSC-5767.jpg
DSC-5770.jpg
DSC-5776.jpg
DSC-5779.jpg
DSC-5784.jpg
DSC-5790.jpg
DSC-5796.jpg
DSC-5801.jpg
DSC-5802.jpg
DSC-5804.jpg
DSC-5809.jpg
DSC-5814.jpg
DSC-5820.jpg
DSC-5821.jpg
DSC-5828.jpg
DSC-5834.jpg
DSC-5837.jpg
DSC-5841.jpg
DSC-5845.jpg
DSC-5850.jpg
DSC-5860.jpg
DSC-5862.jpg
DSC-5868.jpg
DSC-5870.jpg
DSC-5872.jpg
DSC-5878.jpg
DSC-5879.jpg
DSC-5886.jpg
DSC-5888.jpg
DSC-5893.jpg
DSC-5899.jpg
DSC-5900.jpg
DSC-5902.jpg
DSC-5904.jpg
DSC-5907.jpg
DSC-5908.jpg
DSC-5914.jpg
DSC-5916.jpg
DSC-5922.jpg
DSC-5924.jpg
DSC-5925.jpg
DSC-5926.jpg
DSC-5929.jpg
DSC-5931.jpg
DSC-5932.jpg
DSC-5933.jpg
DSC-5935.jpg
DSC-5937.jpg
DSC-5938.jpg
DSC-5941.jpg
DSC-5942.jpg
DSC-5944.jpg
DSC-5945.jpg
DSC-5949.jpg
DSC-5950.jpg
DSC-5952.jpg
DSC-5953.jpg
DSC-5955.jpg
DSC-5956.jpg
DSC-5957.jpg
DSC-5959.jpg
DSC-5962.jpg
DSC-5964.jpg
DSC-5966.jpg
DSC-5968.jpg
DSC-5972.jpg
DSC-5973.jpg
DSC-5976.jpg
DSC-5977.jpg
DSC-5979.jpg
DSC-5984.jpg
DSC-5985.jpg
DSC-5987.jpg
DSC-5992.jpg
DSC-5998.jpg
DSC-5999.jpg
DSC-6000.jpg
DSC-6002.jpg
DSC-6003.jpg
DSC-6005.jpg
DSC-6007.jpg
DSC-6009.jpg
DSC-6013.jpg
DSC-6014.jpg
DSC-6017.jpg
DSC-6018.jpg
DSC-6021.jpg
DSC-6023.jpg
DSC-6032.jpg
DSC-6033.jpg
DSC-6037.jpg
DSC-6041.jpg
DSC-6046.jpg
DSC-6048.jpg
DSC-6049.jpg
DSC-6052.jpg
DSC-6054.jpg
DSC-6055.jpg
DSC-6059.jpg
DSC-6062.jpg
DSC-6065.jpg
DSC-6067.jpg
DSC-6070.jpg
DSC-6075.jpg
DSC-6076.jpg
DSC-6080.jpg
DSC-6083.jpg
DSC-6086.jpg
DSC-6089.jpg
DSC-6091.jpg
DSC-6093.jpg
DSC-6095.jpg
DSC-6096.jpg
DSC-6099.jpg
DSC-6104.jpg
DSC-6106.jpg
DSC-6107.jpg
DSC-6108.jpg
DSC-6110.jpg
DSC-6112.jpg
DSC-6113.jpg
DSC-6114.jpg
DSC-6115.jpg
DSC-6116.jpg
DSC-6119.jpg
DSC-6120.jpg
DSC-6122.jpg
DSC-6133.jpg
DSC-6140.jpg
DSC-6141.jpg
DSC-6142.jpg
DSC-6147.jpg
DSC-6148.jpg
DSC-6150.jpg
DSC-6154.jpg
DSC-6157.jpg
DSC-6160.jpg
DSC-6163.jpg
DSC-6164.jpg
DSC-6172.jpg
DSC-6174.jpg
DSC-6180.jpg
DSC-6183.jpg
DSC-6191.jpg
DSC-6192.jpg
DSC-6199.jpg
DSC-6205.jpg
DSC-6211.jpg
DSC-6212.jpg
DSC-6215.jpg
DSC-6217.jpg
DSC-6221.jpg
DSC-6228.jpg
DSC-6230.jpg
DSC-6233.jpg
DSC-6235.jpg
DSC-6240.jpg
DSC-6241.jpg
DSC-6254.jpg
DSC-6262.jpg
DSC-6265.jpg
DSC-6276.jpg
DSC-6279.jpg
DSC-6280.jpg
DSC-6288.jpg
DSC-6292.jpg
DSC-6293.jpg
DSC-6295.jpg
DSC-6301.jpg
DSC-6302.jpg
DSC-6306.jpg
DSC-6307.jpg
DSC-6309.jpg
DSC-6310.jpg
DSC-6314.jpg
DSC-6319.jpg
DSC-6320.jpg
DSC-6330.jpg
DSC-6335.jpg
DSC-6337.jpg
DSC-6338.jpg
DSC-6339.jpg
DSC-6342.jpg
DSC-6345.jpg
DSC-6347.jpg
DSC-6352.jpg
DSC-6354.jpg
DSC-6367.jpg
DSC-6369.jpg
DSC-6370.jpg
DSC-6371.jpg
DSC-6373.jpg
DSC-6375.jpg
DSC-6376.jpg
DSC-6377.jpg
DSC-6380.jpg
DSC-6386.jpg
DSC-6391.jpg
DSC-6393.jpg
DSC-6395.jpg
DSC-6396.jpg
DSC-6397.jpg
DSC-6398.jpg
DSC-6400.jpg
DSC-6404.jpg
DSC-6406.jpg
DSC-6414.jpg
DSC-6421.jpg
DSC-6424.jpg
DSC-6428.jpg
DSC-6432.jpg
DSC-6435.jpg
DSC-6436.jpg
DSC-6439.jpg
DSC-6441.jpg
DSC-6443.jpg
DSC-6446.jpg
DSC-6447.jpg
DSC-6450.jpg
DSC-6451.jpg
DSC-6452.jpg
DSC-6455.jpg
DSC-6457.jpg
DSC-6458.jpg
DSC-6459.jpg
DSC-6461.jpg
DSC-6464.jpg
DSC-6466.jpg
DSC-6468.jpg
DSC-6469.jpg
DSC-6472.jpg
@dergachev
Copy link
Author

And if that fails, here's another approach:

ls -al

# current directory contains files.txt, DSC-6452.jpg, DSC-6453.jpg, ...

mkdir picks/
# xargs syntax works on OSX; might be different on linux
cat files.txt  | xargs -J FILES_PATTERN echo mv 'FILES_PATTERN' picks/

# copy and paste resulting command to run it

@dergachev
Copy link
Author

OK turns out the photographer renamed the photos on export, and so the JPG file names are useless.
Instead, we need to work with timestamps:

# install a photo metadata extraction tool, via homebrew on OS X
brew intall exiftool

cd $RAWFOLDER

for FILE in *.dng ; do echo `exiftool -CreateDate "$FILE" | awk '{ print $5}'` $FILE ; done | tee inventory-raw.txt

head -n 3 inventory-raw.txt 
#    15:43:27 _DSC0489.dng
#    15:44:29 _DSC0494.dng
#    15:44:55 _DSC0497.dng

awk '{print $1}' inventory-raw.txt > inventory-raw-bare.txt

head -n 3 inventory-raw-bare.txt 
#    15:43:27
#    15:44:29
#    15:44:55

cd $JPGFOLDER
for FILE in *.jpg ; do echo `exiftool -CreateDate "$FILE" | awk '{ print $5}'` $FILE ; done | tee inventory-jpg.txt

head -n 3 inventory-jpg.txt
#    13:37:50 DSC-5767.jpg
#    13:37:57 DSC-5770.jpg
#    13:38:13 DSC-5776.jpg

awk '{print $1}' inventory-jpg.txt > inventory-jpg-bare.txt

head -n 3 inventory-jpg-bare.txt
#    13:37:50
#    13:37:57
#    13:38:13

mv inventory-jpg.txt inventory-jpg-bare.txt $RAWFOLDER

cd $RAWFOLDER

ls *.txt
#    inventory-jpg.txt
#    inventory-jpg-bare.txt
#    inventory-raw.txt
#    inventory-raw-bare.txt

# this displays all the files in inventory-jpg.txt WITHOUT matching timestamps in inventory-raw-bare.txt
grep -Fvf inventory-raw-bare.txt inventory-jpg.txt | sort | tee inventory-missing-raw.txt

#    13:38:13 DSC-5776.jpg
#    13:39:55 DSC-5801.jpg
#    13:41:52 DSC-5821.jpg
#    13:49:43 DSC-5850.jpg
#    13:51:33 DSC-5868.jpg
#    13:51:54 DSC-5585.jpg
#    13:58:53 DSC-5879.jpg
#    14:42:15 DSC-5888.jpg
#    15:42:30 DSC-6070.jpg
#    16:53:36 DSC-6154.jpg
#    17:02:26 DSC-6174.jpg
#    17:05:33 DSC-6180.jpg
#    17:21:10 DSC-6221.jpg
#    18:08:18 DSC-6376.jpg


# this displays all the files in inventory-raw.txt WITHOUT matching timestamps in inventory-jpg-bare.txt
grep -Fvf inventory-jpg-bare.txt inventory-raw.txt | sort | tee inventory-extra-raw.txt

#    13:51:32 _DSC0141-2.dng
#    13:51:43 DSC_5584.dng
#    14:42:21 _DSC0163-2.dng
#    15:04:00 DSC_5685.dng
#    15:42:20 _DSC0481.dng
#    17:05:31 _DSC0104.dng
#    18:08:01 DSC_5791.dng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment