An AppleScript to reduce large Word file sizes

May 21, '03 09:32:00AM

Contributed by: Safar

As you may know, Microsoft Word has the habit of messing up with big documents. As you work on them, they get bigger and bigger, and often a day comes when word starts crashing the document. This is because Word remembers everything you do to your document. For instance, if you add an image, save and close your document, open again your document, delete your image, save your document, your file will be much bigger than before, even though the image is no longer there. This is because word will remember that you added an image and then deleted it.

The solution is to:

  1. Open your document in word
  2. Select all your text
  3. Copy all your text
  4. Create a new document
  5. Paste all your text
  6. Save the copy, and delete the original
This can do wonders for your file sizes! I have already reduced by ten times some of my largest documents using this trick. So I spent the evening writing this little AppleScript to do the work for me.

Read the rest of the hint for the script.

on open (theItems)
  repeat with aFile in theItems
    tell application "Finder"
      set fileRef to (a reference to file aFile)
      set FileName to fileRef as string
      tell application "Microsoft Word"
        activate
        open fileRef
        set mic to select text of last document
        copy
        close last document
        tell application "Finder"
          move fileRef to trash
        end tell
        make new document
        paste
        save last document in FileName
        close last document
      end tell
    end tell
  end repeat
end open
To use the script, open Script Editor, copy and paste the script, and save it as an application. Then drag and drop (onto the script icon) the Word documents you want to clean up (but nothing else!). I hope some will find it useful.

[robg adds: I haven't tested this script myself, but it looks quite straightforward.]

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030519172755835