Write All Keywords to Text File

This is a snippet that exports a list of all keywords encountered in the currently loaded library to a text file. Hierarchical keywords will be written as an indented tree with tab characters used for indentation.

2025/09/27: Updated to output in Lightroom Classic compatible format and to sort case insensitively

// Write All Keywords to Text File

var lines = []
function collect_keywords(kwds, prefix) {
	var kwds_sorted = []
	kwds.forEach(function(kw) {
		if (kw.kind() == "normal")
			kwds_sorted.push(kw)
	})
	kwds_sorted.sort(function(a, b) {
		ak = a.keyword().toLowerCase()
		bk = b.keyword().toLowerCase()
		return ak.localeCompare(bk)
	})
	
	for (i in kwds_sorted) {
		lines.push(prefix + kwds_sorted[i].keyword())
		collect_keywords(kwds_sorted[i].children(), prefix + "\t")
	}
}
collect_keywords(library.rootNode().keywords(), "")
var text = ""
for (i in lines) text += lines[i] + "\n"

var path = chooseFile({
	save: true,
	formats: [{
		name: "Text Files",
		patterns: ["*.txt"]
	}]})
if (path != "")
	writeFileUTF8(path, text)

Installation

  1. Copy the snippet source code above to the clipboard
  2. In Aspect, go to the “Snippets” page of the settings dialog and click “Add Snippet…”
  3. Paste the source code into the “Source Code” area - the “Menu Entry” field will be filled out automatically

The new menu entry should now be visible in the “File” menu and you can also optionally assign a keyboard shortcut in the “Shortcuts” section of the settings dialog.

Very interesting snippet. In my workflow, I use the Keywords list a lot to find and correct small writing errors at a glance. When Aspect is up and running, I’ll try it out. I’m trying to get it to work on Linux (Fedora or Debian) with my photos stored on a Qnap NAS, but something always goes wrong.

I’m trying to get it to work on Linux (Fedora or Debian) with my photos stored on a Qnap NAS, but something always goes wrong.

Because I ran into issues there, how do you have the NAS folder mounted locally? At least the GVFS user mounts unfortunately do not support modifying large files, so they are fundamentally incompatible with the metadata/thumbnail cache. I switched to using the server version of Aspect instead of trying to get it to work this way, but that’s probably not an option in your case.

Of course it’s an option! I’ll try Aspect Server these days. Thanks and saludos,

I just meant because it probably can’t run on the QNAP directly – once we have a Linux/aarch64 version, that might change, though.