Created
July 8, 2020 15:22
-
-
Save robmiller/0f6505611774d33231621c3a73703c82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# lightroom-groups.rb | |
# Author: Rob Miller <r@robm.me.uk> | |
# | |
# Mass organises presets into groups in Lightroom, based on their folder | |
# on disk. | |
# | |
# -- | |
# | |
# Lightroom is a pain in the arse when it comes to managing presets. It | |
# would be nice if you could just sort them into folders and have | |
# Lightroom respect that structure, but no – the folder is stored in the | |
# XMP metadata for the preset itself, and the interface for managing the | |
# folders is awful – you have to right click, "Move", select the folder, | |
# click OK, etc. for each and every preset. No thanks. | |
# | |
# This script takes the structure of the folders on disk, and sets the | |
# metadata of the presets accordingly. So put the presets into the right | |
# folders – from "User Presets" to whatever else you want – and then, | |
# once you're happy with it on disk, run this script. It'll blitz | |
# through and update the group of the preset to reflect the name of the | |
# folder it's in. Simple. | |
# | |
# -- | |
# | |
# I DO NOT ACCEPT RESPONSIBILITY IF THIS SCREWS UP YOUR PRESETS IN ANY | |
# WAY, IT WORKED FOR ME BUT IT MIGHT NOT WORK FOR YOU | |
gem "nokogiri", "~> 1.10" | |
require "nokogiri" | |
folders = Dir["*"].find_all { |f| Dir.exist?(f) && f != "User Presets" } | |
folders.each do |folder| | |
Dir["#{folder}/*.xmp"].each do |file| | |
xml = Nokogiri::XML(File.read(file)) | |
group_name = xml.at_xpath("//crs:Group/rdf:Alt/rdf:li", | |
"x" => "adobe:ns:meta/", | |
"rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", | |
"crs" => "http://ns.adobe.com/camera-raw-settings/1.0/") | |
unless group_name | |
$stderr.puts "Couldn't find a group name for #{file}" | |
next | |
end | |
group_name.content = folder | |
File.open(file, "w") do |write| | |
puts "Writing XML to #{file}" | |
write.write(xml.to_s) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment