MaxWMcKinley
MaxWMcKinley

Reputation: 13

Applescript help. Program won't end

So I'm new to applescript and I'm trying to create an app that will open microsoft word and then save the document every once in a while automatically and then stop running once I close Word. This is my code so far:

activate application "Microsoft Word"

     if application "Microsoft Word" is running then

          repeat

               delay 5

               tell application "Microsoft Word" to save front document

         end repeat

     end if

It works up until the point that I quit word. Even though I have it set to end if word isn't running it still tries to save to word and then I get an error message. Another interesting thing to note is that it even says end tell in the script once I quit word.

What am I doing wrong?

Upvotes: 1

Views: 165

Answers (1)

adayzdone
adayzdone

Reputation: 11238

Save this as a stay-open application:

activate application "Microsoft Word"

    on idle
        say "idle"
        if application "Microsoft Word" is running then tell application "Microsoft Word" to save front document
        return 5 -- in seconds
    end idle

Upvotes: 2

Related Questions