If your python script begins with #!/usr/bin/python, then you do not need to explicitly invoke python in the do shell script. The external Python script does need to be executable: chmod +x python_creator.pdf. Get in the habit of using the underscore with filenames in the shell, as '-' and space have special meaning to Bash.
Both of the script approaches will change the creator attribute to your creator_string. The second version is very sensitive to correct syntax spacing, and escaping any characters (e.g. double-quotes, or '\' characters) that AppleScript will eat, and break the code. Both of the following scripts were tested on El Capitan 10.11.6 with the system Python.
property creator_string : "My creator revision"
tell application "Finder"
if not (get selection) = {} then
set finderSelectionList to (selection as alias list)
else
display alert "Nothing selected in the Finder." giving up after 10
return
end if
end tell
repeat with theFile in finderSelectionList
set a to (POSIX path of theFile)'s quoted form
set args to a & space & a & space & creator_string's quoted form
do shell script "~/Desktop/PDF_creator.py " & args
end repeat
return
property creator_string : "My creator revision"
tell application "Finder"
if not (get selection) = {} then
set finderSelectionList to (selection as alias list)
end if
end tell
repeat with theFile in finderSelectionList
set a to (POSIX path of theFile)'s quoted form
set args to a & space & a & space & creator_string's quoted form
change_pdf_creator(args)
end repeat
return
on change_pdf_creator(theArgs)
return do shell script "python <<'EOF' - " & theArgs & "
#!/usr/bin/python
# coding: utf-8
from Foundation import NSURL, NSMutableDictionary
from Quartz import PDFDocument, PDFDocumentCreatorAttribute
import os
import sys
def main():
if len(sys.argv) != 4:
sys.exit(1)
in_PDF = os.path.expanduser(sys.argv[1])
out_PDF = os.path.expanduser(sys.argv[2])
creator_str = sys.argv[3]
url = NSURL.fileURLWithPath_(in_PDF)
pdfdoc = PDFDocument.alloc().initWithURL_(url)
attrs = NSMutableDictionary.alloc().initWithDictionary_(pdfdoc.documentAttributes())
attrs[PDFDocumentCreatorAttribute] = creator_str
pdfdoc.setDocumentAttributes_(attrs)
pdfdoc.writeToFile_(out_PDF)
if __name__ == '__main__':
sys.exit(main())
EOF"
end change_pdf_creator