The script is supposed to insert three lines of text at the very beginning of the file.
I don’t use Mer.Soft products so I can’t test.
Insert two extraneous instructions flagged # ADDED below :
repeat with theFile in myFileList
set _counter to _counter + 1
set filePathPosix to quoted form of (POSIX path of theFile)
set shCMD to "textutil -noload " & filePathPosix & " -stdout -format docx -convert txt -encoding UTF-8"
set docText to do shell script shCMD
log docText # ADDED
set theEmailAddress to fnd(“\b[A-Z0-9._%±]+@[A-Z0-9.-]+\.[A-Z]{2,}\b”, docText, false, true) of me
set headerText to "Name: " & text item 1 of (item _counter of myNameList) & return & "Email: " & theEmailAddress & return & return
log ">>>>>>> " & headerText # ADDED
tell application “Microsoft Word”
open theFile
tell active document
tell its text object
insert text headerText at beginning
end tell
save
close
end tell
end tell
end repeat
When you will run the script they will display some datas in the Events log area at the bottom of the Editor’s window.
If the Events log pane is not displayed, click the small blue square with four horizontal lines available at the very bottom of the window.
Looking at this events log, you will be able to see if the script correctly extract the wanted datas.
Given my experience, ccstone never post a script before testing it so I’m quite sure that if your documents contain the searched datas, it will insert them at the beginning of the document.
As you wrote that the script opened three Word documents, it’s clear that it built the wanted headers.
Just a question : are the documents large ones ?
If they are, maybe it would be useful to insert a delay between the instruction : open theFile
and the instruction : tell active document:
You may also temporarily force the script to stop after inserting datas in the first docx treated.
The code will then looks like that :
tell application “Microsoft Word”
open theFile
delay 1 # ADDED
tell active document
tell its text object
insert text headerText at beginning
end tell
save
error number -128 # ADDED
close
end tell
end tell
With these tips you would be able to see what is really done.
Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) lundi 4 janvier 2016 18:12:42