Hello again,
I am more and more intrigued. I found a document in Internet (in
Japanese) explaining AppleScript scripting with MS Word. It says:
You can execute an AppleScript like this:
save as active document file name "Temp.doc"
where file name must be the name of the file or its file path.
So, I tried the following code:
set fpath to "Macintosh HD:Users:[me]:Documents:Backup:mydocfile.doc"
set convert_fpath to "Macintosh HD:Users:[me]:Documents:mydocfile.rtf"
tell application "Microsoft Word"
activate
open fpath
save as active document file name convert_fpath file format format rtf
close active document
end tell
and it worked perfectly. Then I tried:
set fpath to "Macintosh HD:Users:[me]:Documents:Backup:mydocfile.doc"
set convert_fpath to my replace_doc_with_rtf_MacPath(fpath)
tell application "Microsoft Word"
activate
open fpath
save as active document file name convert_fpath file format format rtf
close active document
end tell
on replace_doc_with_rtf_MacPath(fpath)
set perl_scpt to "$_ = shift; s/\\.doc$//; s/$/\\.rtf/; print;"
return (do shell script "perl -e '" & perl_scpt & "' " & quoted form
of fpath)
end replace_doc_with_rtf_MacPath
Now, it says:
Microsoft Word got an error: active document doesn't understand the
save as message.
I don't understand at all. What am I doing wrong...?
Thank you in advance for any insight.
Best regard,
Nobumi Iyanaga
Tokyo,
Japan
On Jun 5, 2010, at 1:35 PM, Nobumi Iyanaga wrote:
> Hello,
>
> As the title line says, I would like to make a droplet which
> convert a ".doc" file into a ".rtf" file, in the same folder.
>
> I always used to use this code:
>
> tell application "Microsoft Word"
> activate
> try
> open theFile
> tell front document
> set fname to get name
> set fname to my replace_doc_with_rtf(fname)
> save as file name (fname) file format format rtf
> close
> end tell
> on error errMsg
> display dialog errMsg
> return
> end try
> end tell
>
> on replace_doc_with_rtf(fname)
> set perl_scpt to "$_ = shift; s/\\.doc$//; s/\\./_/g; s/$/\\.rtf/;
> print;"
>
> return (do shell script "perl -e '" & perl_scpt & "' " & quoted
> form of fname)
> end replace_doc_with_rtf
>
> and it worked without problem, but I suddenly realized that it
> saves the converted file in the folder that was used the last time
> to save a file -- so that this code can surely work only when Word
> is launched just before. Otherwise, if Word saved a file in a
> different folder, in the current session, it will save the
> converted file in that folder.
>
> MS Word scripting dictionary says:
>
> save v : Save an object
> save reference : the object to save
> [in alias] : the file in which to save the object
> [as type class] : the file type of the document in which to save
> the data
>
> I tried something like
>
> tell application "Microsoft Word"
> activate
> open theFile
> tell front document
> set fname to get name
> set fname to my replace_doc_with_rtf(fname)
> save in xxx as file name (fname) file format format rtf
> close
> end tell
> end tell
>
> But this does not compile. And the dictionary term "[in alias]"
> seems odd, because the new file cannot be an alias, as far as I
> understand.
>
> Could any of you indicate me how to specify a folder in such cases?
>
> Thanks in advance.
>
> Best regard,
>
> Nobumi Iyanaga
> Tokyo,
> Japan
|