Last active
January 6, 2023 21:18
-
-
Save tjluoma/ca9bcbe0d905a759442f to your computer and use it in GitHub Desktop.
I use this with a Keyboard Maestro macro that runs whenever MSWord “deactivates” (in Keyboard Maestro terms). Updated with comments from http://apple.stackexchange.com/a/132171/9226
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on hasDocument() | |
tell application "Microsoft Word" | |
every document is not missing value | |
end tell | |
end hasDocument | |
tell application "Microsoft Word" | |
if it is running and my hasDocument() then | |
save active document | |
end if | |
end tell |
Hrm for some reason I can’t see RobTrew’s comment anymore.
Fortunately I saved it. He suggested:
tell application "Microsoft Word"
if running then
if documents is not missing value then
tell active document
if (not saved and path contains ":") then save
end tell
end if
end if
end tell
And in case you wanted to log the saves, you could try a pattern something like this:
SaveMSDoc()
on SaveMSDoc()
set strReturn to "Nothing to save ..."
tell application "Microsoft Word"
if running then
set lstDocs to documents
if lstDocs is not missing value then
set oDoc to active document
if oDoc is missing value then set oDoc to item 1 of lstDocs
tell oDoc
set strPath to path
if (not saved and strPath contains ":") then
save
set strReturn to ((current date) as string) & tab & "saved " & strPath
end if
end tell
end if
end if
end tell
return strReturn
end SaveMSDoc
Hi TJ - I did delete the first version :-) it didn't take account of the fact that .active_document can return missing value even when the document list is not empty ...
罗斌洲
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @RobTrew! I like that even better, and it incorporates another suggestion from https://twitter.com/ComplexPoint/status/471715614965657601