Close all windows / documents and do not save macro not working

Macro is attached.

I do a lot of testing in BBEdit, and end up with many open documents.

Those documents which I want to save are already saved, and I want to close the other documents without saving

Objective of the macro:

  • Close all documents
  • if document was already saved and no Save Don't Save buttons appear, close document and go to the next one to close it.
  • if document was not saved, Save Don't Save buttons will appear in which case Press Don't Save and go to the next Document

thanks in advance for your time and help

Close All do NOT Save - Documents Windows .kmmacros (21.2 KB)

I think your objective can be met using the BBEdit built-in menu, File > Close All Documents (hold down OPT key):

image

1 Like

Let me ask a clarification question: are you saying:

  1. That there are no unsaved changes at this point, and you just want to close everything because you are absolutely sure that any changes you wanted to save are already saved?

or

  1. There may be unsaved changes in files that you want to save, but those files will have previously been saved (and will therefore have a given filename already), so you want to save those files, but close any untitled documents without saving them?

This is an AppleScript that I have from the BBEdit user group (mailing list) which will:

  1. Automatically save all previously-saved files using their previously given filenames

  2. Not try to save any files which have not been previously saved:

-- With thanks to Christopher Stone and Rich Siegel 
-- Source: https://groups.google.com/d/topic/bbedit/dfT5wJY5wSI/discussion

if application "BBEdit" is running then
	try
		tell application "BBEdit"
			set docList to (text documents whose on disk is true and modified is true)
			repeat with theDoc in docList
				save theDoc
			end repeat
		end tell
	end try
end if

(Aside: I have a Keyboard Maestro macro that runs that AppleScript whenever BBEdit deactivates and every 1 minute while BBEdit is active.)

I would assume that it would be fairly easy to modify that AppleScript to:

  1. Close the file after saving it (if it needs to be saved, by the criteria already specified)
  2. Close the rest of the files without prompting you to save them.

However, I do not speak AppleScript well enough to tell you how to do that.

My recommendation would be to ask on the BBEdit user group because someone there will certainly know the best way to do this.

If, by some weird chance, you do not get a good answer there, I would contact BBEdit support directly because they will 100% know the answer.

(Why try the user group first? Because then others can benefit from the discussion and answer(s) that are given.)

1 Like

thank you very much. I did not know about the Opt menu and how close all works.

I greatly appreciate your comments. I want to close all because I saved what's important. That being said, my method does not provide a failsafe in case I forgot to save one of 60 documents.

I think that @JMichaelTX's method using the Opt menu is optimal.
Ability to close all quickly + a quick glance at those files which will be closed without saving.

I hope that you will not be offended that I don't take the script route.

thanks very much

image

thanks again. I can write a macro with a simple keystroke, but for didactic reasons only, how do you access a menu item which only appears when you press the Opt key ?

Not in the least! Everyone should choose the option that fits them best.

I think Keyboard Maestro's menu item list should show all of the menu items, but if it doesn't then I would just fine one that is close, use that, and then edit the last line to match what you want. Be careful of capitalization and spelling, both of which have to be precise.

1 Like

@tjluoma is correct:

image

1 Like

Thank you both @JMichaelTX and @tjluoma for both solutions (see directly or modify the menu)

There is one situation which remains obscure: when the context menu changes when the option key is pressed.

Example: the Evernote context menu when you right click in the Notes List.

As per illustration 1, below, Copy Note Link becomes Copy Classic Note Link (much much more useful) if I press on the option key as I trigger the context menu.

A while back I tried in vain to create a macro to do so.

The following does not work:

  • finding a new item: there is none
  • the right mouse click with option button action
  • just now after reading @tjluoma's post today I tried modifying the menu item (Copy Note Link) but it did not work : error message = menu item not found.

thank you

2020-02-01_20-18-24%20(1)

First, context menus and normal menus (in the Apple bar) are different, and are handled differently. It is up to the app developer to provide consistency, which Evernote does not.

Second, Evernote uses the dynamic menu approach, which means that the menu items are NOT available to KM (or AppleScript) until the menu is actually shown.
In this case the OPT key causes a new/different menu item.

image

You will need to use AppleScript to create the classic link by other means. I think I have provided this to you previously.

1 Like

Indeed the AppleScript is the solution.
My question was specifically about using KBM actions to tackle dynamic menus and context dynamic menus. I just happened to take Evernote as an example, not a specific request about Evernote.
thank you for your comment

KM can't really help with this. It takes an AppleScript to tell the app UI to show the menu (perform action "AXShowMenu"), or click on the parent menu to show it.

1 Like