Replace author in docx files

docx_author

Install python-docx and parallel:

$ sudo apt install python-docx parallel

Save this code as /usr/local/bin/docx_author:


#!/usr/bin/env python
'''
Requirements: python-docx, parallel
Usage: docx_author 'Putin\ Huilo' file.docx
find /home/user/some_dir -type f -name "*\.docx" | parallel docx_author 'Putin\ Huilo'
'''
from docx import Document
import sys
print(sys.argv[2] + ' author changed to ' + sys.argv[1])
document = Document(sys.argv[2])
core_properties = document.core_properties
core_properties.author = (sys.argv[1])
document.save(sys.argv[2])

Make it executable:


sudo chmod +x /usr/local/bin/docx_author

Use it on single docx:


$ docx_author 'Putin\ Huilo' file.docx

Here is an example on multiple files:
$ find /home/vitich/test -type f -name "*\.docx" | parallel docx_author 'Putin\ Huilo'
/home/vitich/test/file-sample_500kB.docx author changed to Putin Huilo
/home/vitich/test/test.docx author changed to Putin Huilo
/home/vitich/test/test2.docx author changed to Putin Huilo