Skip to content

Instantly share code, notes, and snippets.

@mrtnvgr
Created May 15, 2025 14:59
Show Gist options
  • Save mrtnvgr/3999346c9895d207bdfbd87453dcfb0a to your computer and use it in GitHub Desktop.
Save mrtnvgr/3999346c9895d207bdfbd87453dcfb0a to your computer and use it in GitHub Desktop.
Generate registy entries for NI Kontakt libraries
#!/usr/bin/env python3
# (Tested on Kontakt 7, may not work for future versions)
# 1. Run in the directory with your Kontakt libraries
# 2. Save the generated text into a .reg file, import it
import glob
import xml.etree.ElementTree as ET
import os
from dataclasses import dataclass
from functools import cache
@dataclass
class Product:
name: str
version: str
HU: str
JDX: str
visibility: str
def get_version(version: int) -> str:
version += 99
digits = map(lambda x: x, str(version))
return ".".join(digits)
def get_product(data: str) -> Product:
root = ET.fromstring(data)
version = get_version(int(root.find("Product").get("version")))
name = root.find("Product/Name").text
specific = root.find("Product/ProductSpecific")
hu = specific.find("HU").text
jdx = specific.find("JDX").text
visibility = specific.find("Visibility").text
return Product(name, version, hu, jdx, visibility)
def generate_reg_part(product: Product, path: str) -> str:
content_dir = "Z:" + path.replace("/", r"\\")
visibility = "dword:" + product.visibility.rjust(8, "0")
part = []
part.append(f"[HKEY_LOCAL_MACHINE\\Software\\Native Instruments\\{product.name}]")
part.append(f'"ContentDir"="{content_dir}"')
part.append(f'"ContentVersion"={product.version}')
part.append(f'"HU"="{product.HU}"')
part.append(f'"JDX"="{product.JDX}"')
part.append(f'"Visibility"={visibility}\n')
return "\n".join(part)
def generate_reg(reg_parts: str) -> str:
reg = []
reg.append("Windows Registry Editor Version 5.00\n")
reg.append("[HKEY_LOCAL_MACHINE\\Software\\Native Instruments]\n")
reg.extend(reg_parts)
return "\n".join(reg)
libraries = glob.glob("**/*.nicnt", recursive=True)
reg_parts = []
for library in libraries:
with open(library, "rb") as nicnt:
nicnt.read(256) # skipping header
# reading xml info
xml_bytes = b""
while not xml_bytes.endswith(b"</ProductHints>"):
xml_bytes += nicnt.read(1)
xml_data = xml_bytes.decode()
product = get_product(xml_data)
library_path = os.path.abspath(os.path.dirname(library))
reg_part = generate_reg_part(product, library_path)
reg_parts.append(reg_part)
print(generate_reg(reg_parts))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment