How can I set Spotlight metadata to files? I am looking for a command line utility (I need to use it in a script) that can set Spotlight metadata to files.
You can always use the command line tool xattr, which lists/reads/writes/erases the filesystem's extended attributes of a file.

That's what spotlight uses to build it's index.

Note that spotlight information keys are prefixed with com.apple.metadata:

As quick example, to change the display name on spotlight of a file:

xattr -w com.apple.metadata:kMDItemDisplayName MyNewFilename.txt ActualFile.txt


to access xattr help, type on t:

xattr -h