How can script will auto run on attaching a gameobject in editor?

I have a func with a contextMenu attribute. Every time i have to attach this to a game object afterward i have to click on GenerateSomething. (Lazyness whispering me) is there way to make this auto run attaching on a game object?

[ContextMenu("GenerateSomething")] //auto run once on attach?
private void GenerateSomething()
      //spawn something or generate id idk

i found some other solutions to this:

Creating button instead of right click select method
Editor Scripting - Unity Learn

I was thinking this what if i forgot to assign it. which other solution i found is warn yourself

    private void OnEnable() {
        if (id == string.Empty)
            Debug.LogError($"{ } gameObject id is not set!");

this solution below is not recommended but putting it here

//your monobehaviour class

this attribute runs your script’s onawake enable etc. at editor while not in play mode