Automatic creation of specific TAGS



I ask if it is possible to create a script that allows you to generate and assign a specific TAG defined in a button, automatically when the button is pressed.

If there is a concrete possibility to make it work.

Example:

 Window XML: “dialogvideoinfo”
    .
    .
    .
    
       

xml:
<control type="button">
            <label>Set -Family- TAG</label>
            <onclick>RunScript(script.SetTAG, ... query=Family)</onclick>
        </control>

        
        
    —-
    script name: “SetTAG” 
    
    … (write in python) …
    
       
    —-

Result:

The movie or TV series in focus in dialogvideoinfo now has the TAG “Family”

This allows me to automatically create lists of Movies or TV series corresponding to a specific category, and use a smart playlist as a folder.

I know the manual step of setting the TAGs inside the skin, but there is a big problem that led me to try to develop this script:
if the last movie or TV series of a specific TAG is removed, the TAG is deleted and must be recreated every time.

Any help will be truly appreciated.