Rename separate media attributes' types in Supertool

A small script to rename attributes’ types. It tested on 5k media.

[Gramps SuperTool script file]
version=1

[title]
Rename separate media attributes' types in Supertool

[description]
This script checks each media attribute for any value containing "familysearch". If the attribute key is "URL", it renames the key to "Familysearch URL" and prints the updated key and value.

[category]
Media

[initial_statements]
# Initialize a counter to keep track of updates
count = 0

[statements]
# Retrieve the list of all media attributes
attribute_list = obj.get_attribute_list()

# Iterate through each attribute in the list
for attr in attribute_list:

    # Get the attribute type (key) and value
    key = attr.get_type()
    value = attr.get_value()

    # If the value contains "familysearch" and the key is "URL", rename the key
    if "familysearch" in value.lower() and key == "URL":
        # Set the new key to "Familysearch URL"
        attr.set_type("Familysearch URL")
        count += 1
        # Print the updated attribute information
        print(f"{count}). ID: {gramps_id}, Key: '{key}', Value: '{value}'")

# Print a summary of the total number of updates made
print(f"Total updates: {count}")

[filter]

[expressions]

[scope]
# Apply the script to all media objects
all

[unwind_lists]
False

[commit_changes]
# Commit changes after processing
True

[summary_only]
False

I do not understand why you are doing this task via a SuperTool script when the Types Cleanup Tool exists.

It also has a preview of the Matches to allow editing individual records in addition to the Rename and Remove buttons for mass changes.

That tool renames type totally, but I need rename type only if value is https://familysearch… So, I can define any rename conditions. I can not review all 5k image attributes to define which of them rename to “Familysearch URL”, which leave as “URL” as is.

1 Like

I (somewhat) understand.

I have FamilySearch referenced in different ways. And I’m going to have to find ways to harmonize those.

1 Like