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.