How to programatically add folder to Spotlight "do not index"?
According to an answer here, a folder can be excluded from Spotlight indexing (achieving the same effect as adding it to the Privacy tab, although the folder won't actually be listed there) by either


adding .noindex to the end of the folder's name, or
creating an empty file .metadata_never_index inside the folder (eg with touch folder/.metadata_never_index)


You will need to restart Finder after adding  .metadata_never_index, either killall Finder from Terminal or logout from the Apple menu and then log back in. This method doesn't work in Mojave and later.