Macro to Save and Close Document: How to add "for each open document"


if I have many documents open in Pages → want to save and close all and would like to find a KM proper solution without AppleScript, which actions should I add to the macro below

  • each open document is closed sequentially ie add "for each open document"
  • when no save button appears, the macro is cancelled
  • at the end, a notification appears indicating the number of documents saved and closed
  • would it be useful to have a notification in case of error ?

thank you very much

Save and Close all Windows.kmmacros (2.6 KB)

Try doing it the other way round. As pseudocode:

set docCounter to 0
set savedCounter to 0
while there are documents open
   increment docCount
   close the front document
   if it needs to be saved then
      fill in the dialog and press OK
      increment savedCount
   end if
end while
display dialog including docCount and savedCount

That should be more robust, and if it does error you'll have obvious "remaining documents" on screen for you to process.

1 Like

thanks very much !