SuperTool script, which replaces old titles with new ones

First of all you can use this small SuperTool script to print all source titles:

[Gramps SuperTool script file]
version=1

[title]
SuperTool-Sources

[description]

[category]
Sources

[initial_statements]
count = 0
print("-------------------------------------")

[statements]
print(f"{gramps_id}. {title}")

[filter]

[expressions]

[scope]
all

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False

After running this script, you can copy-paste all the source titles into an AI tool and request formatting or structure changes according to specific rules. The AI should then return a ready-made array for the next SuperTool script, which will replace old titles with the new ones:

[Gramps SuperTool script file]
version=1

[title]
SuperTool-Change Source Titles

[description]
This script modifies the titles of source entries in the Gramps genealogy software. It uses a predefined list of old and new titles, along with Gramps IDs, to ensure accurate updates. If a matching entry is found in the list, the title is updated; otherwise, no changes are made.

[category]
Sources

[initial_statements]
# Print a line for better script output visibility.
print("")

# Predefined list of title transformations.
# Each item contains:
# - gramps_id: The unique ID of the source in Gramps.
# - old_title: The original title as it appears in Gramps.
# - new_title: The transformed title to update the source with.
titles_data = [
    {
        "gramps_id": "S0000",
        "old_title": "Метрична книга, c. Ковалівка, 1883, 1884 рр.",
        "new_title": "Метрична книга. Місце: c. Ковалівка. Дата: 1883 р., 1884 р."
    },
    {
        "gramps_id": "S0737",
        "old_title": "Метрична книга, 1764 р. (с. Біловоди)",
        "new_title": "Метрична книга. Місце: с. Біловоди. Дата: 1764 р."
    },
    # A long source titles list can be added here for more entries.
]

[statements]
# Iterate through the predefined title transformations.
for item in titles_data:
    # Check if both the title and Gramps ID match the current source.
    if item["old_title"] == title and item["gramps_id"] == gramps_id:
        # If a match is found, use the new title for the source.
        new_title = item["new_title"]
        obj.set_title(new_title)

[filter]
# No filter is applied, so the script will consider all sources.

[expressions]
# No custom expressions are used in this script.

[scope]
# Apply this script to all sources.

[unwind_lists]
False

[commit_changes]
# Commit the changes made to the titles in Gramps.
True

[summary_only]
# Generate a detailed output rather than a summary.
False

This process allows you to automate the title updates in Gramps efficiently.

1 Like

The scripts were successfully tested on about 700 sources of real data

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.