8

Is there any way I could configure TextEdit to close the window (through keyboard shortcut) without asking me if I want to save an unsaved file?

Can be another script/program configure globally when triggered with a certain shortcut or just a script for TextEdit.

The reason for doing it is that I have a lot of temporary notes in TextEdit's window and I want to close them as fast as possible.

1
  • If you have a lot of temporary files, you can try to force quit the application. It will save your open files, but won't ask you to save them.
    – Michiel
    Sep 4, 2012 at 10:55

3 Answers 3

5

tell application "TextEdit" to close (windows where name of its document is "Untitled") saving no would close the "Untitled" document without saving it, tell application "TextEdit" to close every document saving no would do the same for all open documents.

You could close the current window with tell application (path to frontmost application as text) to close window 1 saving no. It would close all tabs in some applications that use tabs though.

It's easier to just press ⌘W⌫ in my opinion. You can disable the animation for showing the sheets with defaults write -g NSWindowResizeTime -float 0.001.

5
  • Your first suggestion sounds great, but when I make an AppleScript using this line it doesn't seem to work for me? Is this because my unsaved files are named by the system as "Untitled 1", "Untitled 2", "Untitled 3", etc?
    – tomh
    Nov 19, 2019 at 10:49
  • 2
    @tomh, I have to say putting a bounty on a question that is over 7 years old that already has an accepted answer seems a bit ridiculous, however, to answer your question... Yes, as the AppleScript code presented specifically targets a document named "Untitled". To handle all documents with AppleScript code, use: tell application "TextEdit" to close every document saving no Nov 20, 2019 at 6:03
  • Disagree that it’s ridiculous. I tried what the answer suggested. It didn’t work when I ran it as an AppleScript. I would like to be able to run a single script that closed all windows without prompting to save any of them. When I reopen TextEdit, I’d like none of the documents to reopen. Please can you formulate your script suggestion as an answer and I’ll try it. Many thanks
    – tomh
    Nov 20, 2019 at 6:06
  • ⌘W⌫ doesn't work for me, am I doing something wrong?
    – mastazi
    Jan 5, 2021 at 2:29
  • replying to myself - it actually works sorry. If I understand correctly, ⌘W⌫ basically is the single-step form for ⌘W followed by ⌘⌫ - if you want to quit the app you need to do ⌘Q then ⌘⌫ - but there is no ⌘Q⌫ shortcut.
    – mastazi
    Jan 5, 2021 at 2:37
2

If you hit cmd+option+q to quit the app (or hold down Option while quitting from the main menu), it will give you the option to discard changes in all unsaved windows at once, rather than having to tell it to discard changes in each window individually. This will work with all Apple apps, not just TextEdit.

1
  • 2
    The issue with this is that when you re-open TextEdit, the windows all reopen again?
    – tomh
    Nov 19, 2019 at 10:48
0

Solution 1: Open Script Editor and run the following: tell application "TextEdit" to close windows saving no

Solution 2: If the documents still reopen on next launch, they are most likely saved in iCloud/TextEdit. In order to prevent them from being re-opened:

  1. Quit TextEdit
  2. Archive all the files in the iCloud/TextEdit folder (and/or delete the unwanted Untitled documents).
  3. Delete all but the Archive.zip
  4. Empty Trash
  5. Reopen TextEdit (it should have a clean state).
  6. Unzip the Archive.zip to restore the deleted files.

If your TextEdit session is just Untitled Documents, it might be sufficient to just delete all of them and empty the trash.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .