I’ve never used any of them myself, but you’ll find several promising community plugins if you search with “attachment” or something, like Attachment Name Formatting.
Else is there a way I can run an external script through some command in obsidian?
You can use QuickAdd user scripts for this purpose.
In some cases, you don’t need to create a plugin by yourself, and a QuickAdd macro suffice.
For example, if you set something like the following script to run on the plugin load, any non-markdown file will be renamed right after its creation following the rule you define.
Will this work for when an image is pasted into a note?
That is actually wnat I am trying to do with this. When I paste an image into a note it will auto name it and increment the number at the end