Hello,
I was playing with a built in InDesign Script that exports each story as its own text document. I then wanted to work on a script that would combine all the text documents into one word document. I found the following script online but I am getting an error. See script and error below:
on open theFiles
tell application "Microsoft Word" to set comboDoc to make new document
repeat with i from 1 to (count theFiles)
set theFile to item i of theFiles
set filePath to theFile as Unicode text
tell application "Finder"
set {creaType, fileType} to {creator type, file type} of theFile
set ext to name extension of theFile
set fileName to name of theFile
end tell
if (creaType is "MSWD" and {fileType} is in {"BINA", "W8BN", "s8BN", "W6BN", "s6BN", "RTF "}) or ext = "doc" then
tell application "Microsoft Word"
set comboRange to text object of comboDoc
set collapsedRange to collapse range comboRange direction collapse end
insert file file name filePath at collapsedRange
end tell
end if
end repeat
tell application "Microsoft Word" to activate
end open
The error I am getting is:
Can’t get <> of <> “Word files to combine” of <> “Desktop” of <> bpress" of <>“Users” of <> of application “Finder”.
For the most part, the script makes sense to me, except for the file type line…but the error doesn’t make any sense so I am having trouble trying to troubleshoot it myself.
Any help is appreciated!
thanks
babs
What kind of documents are you trying to combine? I used the slightly modified code below to combine 3 .doc files and it worked fine. All I did was set the script to look in a specific folder for documents and comment out the “on open theFiles” and “end open” lines. The 2nd and 3rd lines are all I added. I did have to make sure I changed the default app for the files back to Word (my default is OpenOffice). My other thought is how are you telling the script what to use for theFiles? That may be where your error is coming from as well.
--on open theFiles
set filePath to "2074:untitled folder" as alias
tell application "Finder" to set theFiles to every file of filePath
tell application "Microsoft Word" to set comboDoc to make new document
repeat with i from 1 to (count theFiles)
set theFile to item i of theFiles
set filePath to theFile as Unicode text
tell application "Finder"
set {creaType, fileType} to {creator type, file type} of theFile
set ext to name extension of theFile
set fileName to name of theFile
end tell
if (creaType is "MSWD" and {fileType} is in {"BINA", "W8BN", "s8BN", "W6BN", "s6BN", "RTF "}) or ext = "doc" then
tell application "Microsoft Word"
set comboRange to text object of comboDoc
set collapsedRange to collapse range comboRange direction collapse end
insert file file name filePath at collapsedRange
end tell
end if
end repeat
tell application "Microsoft Word" to activate
--end open
Hello,
OK- I changed the path to mine and it worked great!!!
Now, question, is it difficult to have it put in a hard return between each document that it brings in…I tried to set AppleScript delimiter’s, but I don’t know enough about that to do it property.
Either way, this works great!!!
thanks so much for this!
babs