Disable the Command-Backspace "Move to trash" keyboard shortcut

7,335

Solution 1

In System Preferences > Keyboard > Keyboard Shortcuts, add a shortcut for Preview (Move Selected PDF Document to Trash) that you are unlikely to type inadvertently, something like ^ ⌥ ⇧⌘ ⎋.

Add Preview Keyboard Shortcut

Solution 2

As an alternative to assigning a different (difficult) shortcut to the menu item, you can assign the Cmd-Delete combination to a harmless menu item, such as Edit » Spelling » Check Spelling as You Type.

The difference is, something harmless happens when you press your shortcut, but no matter what unlikely combination of keys you press, it will never perform the delete operation.

Additionally, the answer with the difficult shortcut only works for the specific PDF menu item variant, not on all variants of the item (e.g. Move Selected Image to Trash). It depends on which behavior you prefer.


The problem is: It's not possible to type Delete/Backspace in the dialog where you assign custom shortcuts. You need to do this via the command line in /Applications/Utilities/Terminal.app:

defaults write com.apple.Preview NSUserKeyEquivalents -dict-add "Check Spelling as You Type" "@\U0008"

The result:

alt text


Many thanks to @Arjan for his collaboration on this completely revised answer.

Share:
7,335

Related videos on Youtube

gakera
Author by

gakera

Updated on September 17, 2022

Comments

  • gakera
    gakera almost 2 years

    I use Preview to view PDF files (duh) and sometimes annotate them as well as search them profusely. I keep using the Command-Backspace combination to try to delete the current line I'm writing in the annotation or to clear the search box, but to my dismay it sends the currently open PDF file to the trash!

    I'm used to Command-Backspace deleting the whole line in other, more write or text-input oriented, software, such as TextEdit even (which I don't really use, but it is another OSX default, so I'd think some consistency is to be expected?) .

    Is there any way to disable this keyboard shortcut in Preview? I don't even need it to do what I expect it to, I just want it to stop deleting my files!

    • gakera
      gakera over 13 years
      Ack I did it again not two seconds after posting this, hahaha I suck.
    • Arjan
      Arjan over 13 years
      (As an aside: officially that is called Delete on a Mac, not Backspace.)
    • gakera
      gakera over 13 years
      @Arjan ugh, as a migrating windows user I don't care about the historical semantics of the Apple keyboard. Backspace is backspace, forward delete is delete which incidentally is fn-backspace on my mbp keyboard. The damn option thing pisses me off to no end, the key is labeled with that broken lazer line thing (pew pew) and also with an "alt" but everybody keeps talking about "option" which is nowhere to be found. And Ctrl as ^ ugh, fml
    • Arjan
      Arjan over 13 years
      but everybody keeps talking about "option" which is nowhere to be found -- exactly the reason why I mentioned it, as an aside. When not knowing the official names, things can get more complicated than needed. That's all!
    • gakera
      gakera over 13 years
      I think this is the start of a long surrender on apple's part, since they're now labeling the alt button as such, and the backspace is just an <- arrow. The official vernacular is bound to change as well. The Command button I can live with, but they might as well just call it the mac button, lol
    • HikeMike
      HikeMike over 13 years
      @gakera It's not a broken pew pew lazerz gun, but (I think) a railway switch (at least easier to remember that way) ;-) --- Regarding your most recent comment, you refer to your "international" keyboard. The US layout has both option and delete printed on the keys. --- Regarding the "Mac" button, Apple removed the apple symbol from the key some time between 2005 and 2008. It's heading in the opposite direction.
  • HikeMike
    HikeMike over 13 years
    This is not application specific, and, if it worked (which I doubt), would break Cmd-Backspace in Finder, Transmit, etc.
  • Arjan
    Arjan over 13 years
    Funny Preview developers: the command could be Move to Trash, Move Selected PDF Document to Trash, Move Selected Image to Trash, ...?
  • Arjan
    Arjan over 13 years
    Funny Preview developers: the command could be Move to Trash, Move Selected PDF Document to Trash, Move Selected Image to Trash, ...?
  • HikeMike
    HikeMike over 13 years
    @Arjan Depending on what kind of document is opened. Makes sense, somewhat, even if it makes remapping more difficult and my answer probably wrong (I didn't expect this and tested with multiple image files).
  • Arjan
    Arjan over 13 years
    I wonder if there's some harmless command that one could map Command-Delete to, instead of trying to map Move .. to Trash command to some other key combination...
  • HikeMike
    HikeMike over 13 years
    @Arjan The problem is that he presses the combination, therefore executing the command. Even opening the inspector would be performed; and the default shortcut (Cmd-I-ish) removed (which is another annoyance). One could edit the nib using the developer tools in earlier versions to remove the shortcut or move it to another command, but this isn't possible anymore ("compiled nib"). Another option would be to intercept the shortcut globally using one of the hotkey managers, but this is, as mentioned, global, leading to Finder and general editor breakage.
  • Arjan
    Arjan over 13 years
    Messing with the nibs (as an aside: plutil -convert xml1 my-compiled-nib.nib, or simply Xcode) surely invalidates the digital signature, opening up new problems if Apple ever decides to really start using those... :-( Maybe something like toggling Edit » Spelling » Check spelling as you type might be a good, harmless, command?
  • Arjan
    Arjan over 13 years
    Amai, then I guess it's indeed going to be multiple hard-to-guess shortcuts for all possible names in the menu... And: Delete, right, not Backspace? ;-)
  • HikeMike
    HikeMike over 13 years
    @Arjan Delete isn't actually printed on the key on my Int'l English keyboard, so I'm keeping the cross-platform name I'm used to, thank you very much. ;-)
  • Arjan
    Arjan over 13 years
    Ooops. Option is not printed on older keyboards either. You're not one of those people I don't talk to because they refer to that key as Alt, are you? ;-)
  • 0xced
    0xced over 13 years
    Yes, absoutely!
  • HikeMike
    HikeMike over 13 years
    @Arjan You do have a point. I use option (see one of my earlier comments on my answer), even though alt is printed on my keyboard. At least I don't have to qualify something else with a forward, and I'm used to the name used for ASCII 0x08.
  • gakera
    gakera over 13 years
    Thank you, this works. I selected the other answer as it matches better with my menu item of "Move Selected PDF Document to Trash" - but both are essentially the same.
  • HikeMike
    HikeMike over 13 years
    @Arjan Any idea what's going on here? I tried to edit the plist of Preview by hand, and added the delete glyph from Character Viewer. click me. Cmd-Backspace still perform the delete operation.
  • Arjan
    Arjan over 13 years
    Shouldn't you delete the existing shortcut as well then? I see that shortcut twice in your screenshot. (Actually, when doing that, no need to map any other menu to that key combination?)
  • HikeMike
    HikeMike over 13 years
    @Arjan The plist of Preview contains the shortcut defined in System Preferences under the key NSUserKeyEquivalents. I didn't modify the nib or anything like that. The existing shortcut should be removed -- that is why I made the screenshot -- it just doesn't work with backspace/"delete" (testing Cmd-D correctly removes the shortcut from Add Bookmark, so either it doesn't work at all with backspace, or I'm doing it wrong. Property List Editor for com.apple.Preview.plist.
  • Arjan
    Arjan over 13 years
    Ah, my bad, I thought you edited the nib indeed. According to Modify Cocoa apps shortcut keys per user: To use other keys, such as Delete, you will have to use their Unicode codes like this: @U0008 which would mean command+Delete. But well, you're looking for Backspace ;-) (The defaults write method is also easier to execute than editing the plist, I guess. I see a nice answer on the horizon!)
  • Arjan
    Arjan over 13 years
    Ah, some say it needs a backslash, that is not in that post. But with or without it, this does NOT work for me:defaults write com.apple.Preview NSUserKeyEquivalents -dict-add '{"Check Spelling as You Type"="@\U0008";}'
  • HikeMike
    HikeMike over 13 years
    @Arjan Except it doesn't work. For one, the Uxxxx must be prefixed with a backslash, e.g. @\U0041 for Cmd-A. @\U0008 doesn't work however, it simply gets ignored. ---- I guess you were quicker...
  • Arjan
    Arjan over 13 years
    (Yup, just noticed. Well, too bad!) In 2004, apparently this worked: defaults write com.apple.finder NSUserKeyEquivalents -dict-add "Secure Empty Trash" "@$~\U0008"
  • Arjan
    Arjan over 13 years
    Odd! This does work, and shows fine in Preview, but just not in the plist editor! defaults write com.apple.Preview NSUserKeyEquivalents -dict-add "Check Spelling as You Type" "@\U0008" (Too bad it does mark the document as non-saved, for some reason...)
  • Arjan
    Arjan over 13 years
    And given defaults read com.apple.Preview NSUserKeyEquivalents, I tested that the following works too: defaults write com.apple.Preview NSUserKeyEquivalents -dict-add "Check Spelling as You Type" "@\\b"
  • HikeMike
    HikeMike over 13 years
    @Arjan Interesting, and definitely good to know. You deserve to make it an answer, or perhaps even a self-answered topic to fully document it, independent of the application in question? What's the proper way to handle something like this on this site?
  • Arjan
    Arjan over 13 years
    Yet another odd thing: it's not shown in System Preferences. (I restarted Dock just in case, but did not restart my Mac.) Anyway, I'm not going to post this, but feel free to add it to yours. An edit would finally allow me to upvote (which I removed after I saw the different names in the menu.) I kind of feel that remapping Command-Delete to something harmless is slightly better than defining new shortcuts for the three (?) known names of that odd menu item, but even then it's not too nice it marks documents dirty, and that System Preferences is oblivious about the changes. Nice exercise!
  • gakera
    gakera over 13 years
    I have no idea what's going on here +cries+
  • HikeMike
    HikeMike over 13 years
    @gakera No problem. I totally revised my (previously duplicate) answer as a result of this discussion to provide real value for you. Everything you need to know is now part of the answer itself. Just ignore these comments.
  • ma11hew28
    ma11hew28 over 13 years
    What's the Unicode for shift + command + delete? I want to map it to a rm -rf automator service. And, will the command work if I replace Preview with finder?
  • HikeMike
    HikeMike over 13 years
    @Matt I'll add it to my answer over there. This comment thread is long enough already.
  • gakera
    gakera over 13 years
    @Daniel ok, thank you. The other answer I still prefer, since after assigning the "difficult shortcut" to the move PDF to trash, the Cmd - Backspace resumes to be what I expect it to, that is delete to the start of the current line, so I'm very comfortable now. But I appreciate the alternative answer, thank you :)
  • ma11hew28
    ma11hew28 over 13 years
    @Daniel, thanks. Actually, command + shift + delete is already being used to empty trash, so how about command + fn + delete?
  • HikeMike
    HikeMike over 13 years
    @Matt I'm working on it. Mac OS X's unfortunately not willing to cooperate. As to your shortcut, Fn+Delete is the Forward Delete. Let's see if we get some regular combination of modifiers + delete right first.
  • Arjan
    Arjan over 13 years
    Another nice option: remove it altogether! Like: defaults write com.apple.Preview NSUserKeyEquivalents -dict-add "Move to Trash" nil (and repeat for the other two menu names that we have found...)
  • HikeMike
    HikeMike over 13 years
    @Arjan Great tip!
  • cregox
    cregox over 13 years
    it's always lovely thinking out of the sphere. :)
  • cregox
    cregox over 13 years
    @Daniel I actually prefer posting over bookmarking or 'favoriting'. :D
  • Kyle
    Kyle over 9 years
    Note: this also works for the Finder. I kept deleting entire folders when I was typing file names.....