The goal is to create a droplet that will allow someone to drag a .doc file and it will quickly resave it as .rtf. By quick i mean it doesn’t have to launch Word – Text edit is a speedy launch, so i’ve been trying to accomplish it via TextEdit. Any other free/elegant approach would be fine too.
However i have a problem with the TextEdit approach. I have automator providing the icon and opening the file in TextEdit, but then i can’t figure out within an applescript how to specify the change to .rtf. i tried one approach where i simply save/renaming the file with “.rtf” substituting “.doc” but i’m not convinced this actually does the conversion. Moreover, i don’t know how to direct the script to overwrite the original file without a dialog. Anyone have any ideas? Help is appreciated.
My approach to “convert DOC files to RTF” would be to use textutil. It would go something like this: (untested)
on open someItems
repeat with anItem in someItems
if name extension of (info for anItem) is "doc" then ¬
try
do shell script "textutil -convert rtf " & quoted form of POSIX path of anItem
on error m number n
error "Error converting "" & POSIX path of anItem & "" to RTF: " & m number n
end try
end repeat
end open
No Word, no TextEdit, no fiddling with file names (it should switch “doc” to “rtf” automatically).
(*
(For Intel Mac / OS 10.4 or higher)
This script allows you to convert .doc files to RTF-files. Save as a droplet.
Note: Automatic numbering, autobullets and automatic foot- or endnotes made with MSWord might get lost.
If you have any comments, suggestions or improvements contact me at
kjeld@puntspatie.nl or check out my website [url=http://www.puntspatie.nl]www.puntspatie.nl[/url]
Thanks to StefanK and Bruce Phillips from macsripter.net.
*)
on open fileList
set numOfFiles to (number of items in fileList) as text
repeat with oneFile in fileList
do shell script "/usr/bin/textutil -convert rtf " & quoted form of POSIX path of oneFile
end repeat
end open
--Choose a folder and convert all Word documents to RTF-files
set theFolder_1 to (choose folder with prompt "Convert Word documents in this folder:")
do shell script "/usr/bin/textutil -convert rtf " & quoted form of POSIX path of theFolder_1 & "*.doc"
do shell script "/usr/bin/textutil -convert rtf " & quoted form of POSIX path of theFolder_1 & "*.DOC"
--Put all converted DOC-files in a folder
tell application "Finder"
set Tlist to list folder (theFolder_1 as alias) without invisibles
set numFolders to ((number of folders in folder theFolder_1) + 1)
set newTFolder to (make new folder of (theFolder_1 as alias) with properties {name:"_Converted DOC-files " & numFolders}) as alias
move (every file of (theFolder_1) whose name ends with ".doc") to folder newTFolder
end tell
display dialog "Files converted" buttons {"Okay"} default button "Okay" giving up after 8