MACSCRPT Archives

June 2010

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Nobumi Iyanaga <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Sat, 5 Jun 2010 13:35:04 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (72 lines)
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

ATOM RSS1 RSS2