On May 29, 2013, at 4:05 PM, Paul Berkowitz <
email@hidden> wrote:
On 5/29/13 1:40 PM, "Lists" <email@hidden> wrote:
I used the Word 2004 scripting guide for the syntax.
Actually, this is highly mysterious. I just looked up the AppleScript Reference for Word 2004, and there's no 'file format flat template' there either! (Nor 'format PDF' either.) In fact, as I best recall, it was a major failing of Word 2004 that there was no way to save as PDF (provided only in 2008). So I really wonder what was going on and where you found that enumeration, or how it was provided.
It's possible that the raw code used to compile to some other words, but now in 2008 and/or 2011 displays as 'flat template' (which could still somehow be in the Dictionary, but hidden, as a deprecated (and now in 2011 non-functioning) enumeration. You may have used a different enumeration, but I don't know what that might have been. The Reference also says you can use other formats: "To save a document in another format, specify the appropriate value for the save format property of the file converter object." Maybe there was once a file converter that did the saving to PDF, before Word had it built in (I dimly recollect something of the sort), although it in turn would have been represented by a number:
Stranger still. The script I posted was from a droplet compiled under Word 2008 and opened on a machine with Word 2011. I went digging for my original script, saved as a text file, and found the following script along with some notes that I had compiled under Word 2008.
(* Microsoft Word 2008 can convert documents to PDF as this script does. Although untested, it looks like Word can convert to other formats as well. This is from Word's dictionary "[file format format document/format template/format text/format text line breaks/format dostext/format dostext line breaks/format rtf/format Unicode text/format HTML/format web archive/format stationery/format custom dictionary/format exclude dictionary/format xml/format documentME/format templateME/format document97/format template97/format PDF/format documentAuto/format templateAuto]" For other formats try changing "file format format PDF" to "file format format rtf" or txt or whatever. You must also change the file extension in the "set filname" line to an appropraite extension for the file type. *IMPORTANT* Links in Word documents are NOT preserved in PDFs generated by Microsoft Word. Use the Pages version of this script if you need to preserve links. *)
on open fillist
set bs to "/"
set d to "-"
tell application "Finder"
set defLoc to container of (item 1 of fillist) as alias
end tell
set destn to choose folder with prompt "You are converting Word files by copying them to PDF files." & return & "Select a location to save converted files." default location defLoc
repeat with lvar in fillist
tell application "Finder"
set theName to name of lvar
set filex to name extension of lvar
set l to length of filex
end tell
set nuname to text 1 thru text item -(l + 1) of theName
if "/" is in nuname then
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to bs
set txtLst to every text item of nuname as list
set AppleScript's text item delimiters to d
set nuname to txtLst as string
set AppleScript's text item delimiters to oldDelims
end if
set filname to (destn as string) & nuname & "pdf"
tell application "Microsoft Word"
launch
open lvar
save as active document file name filname file format format PDF
close window 1 saving no
end tell
end repeat
end open
The save line line changed. Go figure!
Once again, thanks.
J