Attempting to intervene in the "Close" process in MS Word

Have a script that silently and simultaneously saves a Word Document as a docx and as a pdf to a different Folder .

save as active document file name mynewDoc file format document
save as active document file name mypdfnewDoc file format format PDF

Every time the open file is recorded as modified it will also be saved again as pdf.

If the user first saves the file via the File Menu of MSW and then closes it, this process is again successful.

However if the user first closes the file via the window’s red button and then saves via the subsequent “Save” dialog the last iteration of the file cannot be saved as pdf (by this method anyway).

Hence my Query

  1. Is it possible, through scripting, to intervene after a windows red “close” button is clicked ?

The IF statement in the theoretical script below (not -in any way- a solution) demonstrates what I am trying to do.

It would, at first glance, appear possible as most programs will bring up a “Save” dialog after a window’s red “close” button has been clicked - that is, if the user has made any changes. I just want to get there before the “Save” dialog comes up. (though that includes the possibility that the user will throw out the most recent changes

  1. Alternatively and better would be if after the red “Close” button is clicked And the “Save” button of the “Save” dialog is clicked the save as pdf process could be completed. A less elegant solution would be to reopen the file and then save to pdf and close.

  2. Maybe some other solution altogether that has escaped this novice.

—MSW 2008 (Student & Home) No access to Word Automator action to Convert Files

The Non -Solution

on idle
	tell application "Microsoft Word"
	end tell
	tell application "System Events"
		if click button 4 of window "Word Document" of process "Microsoft Word" is true then
			display dialog "Remember to....." with title ("Reminder") buttons {"OK"} default button "OK" cancel button "OK"
		rest of script here

		end if
	end tell
	return 0.1
end idle

Any help or a definitive “No way” much appreciated.


One work-around might be to catch it at the other end.

Save As PDF whenever the file is opened. Don’t worry about it when the file is closed.

Many thanks.

That’s something I hadn’t even thought about !

I will tease that out over the next few days.

In the meantime the following script seemed to offer a solution but at least one drawback is evident.

  1. the dialog box appears behind the document. Is this solvable ?
on idle
	tell application "System Events"
		if enabled of button 4 of window "A New Document" of process "Microsoft Word" is false then
			activate me
			display dialog "Remember to....." with title ("Reminder") buttons {"OK"} default button "OK" cancel button "OK"
		end if
	end tell
	return 0.01
end idle

Also is this type of action (if it proves suitable) suitable for something named launchd ?