How to support this blog?

To support this blog, you can hire me as an OmegaT consultant/trainer, or you can send translation and project management jobs my way.

Search the site:

Everything you wanted to know about modifying application shortcuts, and more...

Modifying application shortcuts

Or, how to spend two hours on your machine on a Sunday morning, when you could go take a walk instead...

Here I talk about an itch I felt the need to scratch this morning, and about 2 applications: CheatSheet, and customShortcuts, and I put a lot of references at the end, so have fun reading!


You can change shortcuts in System Preferences > Keyboard > Shortcuts > App Shortcuts

Most of the things you'll ever need to do can be done there.

But then, some can't.

This morning, I realized that in Mail.app, moving from Delete (Cmd+Del) to Mark as Read (Shift+Cmd+U) when I read and sort my mail, was not what I wanted.

When I read my mail, there are obvious deletes, but a lot of my casual mail can just be not read (discussion lists, where only a few threads are interesting), or specifically marked for later reference. But moving from Cmd+Del to Shift+Cmd+U involves a lot of friction and I want to get rid of that.

I want to have something like:

  • Cmd+Del = Mark as Read (or Mark as Unread, depending on context)
  • Shift+Cmd+Del = Delete
    and since that one is taken by "Erase Deleted Items > In All Accounts...", which I never use, I'd move that item to
  • Alt+Shift+Cmd+Del = Erase Deleted Items > In All Accounts...

That way, I have my morning "mail discussion parsing" workflow all centered on Del, which is a Good Thing™.

The problem is that the System Preference panel has its ideas on what can and cannot be done, and won't allow us to assign Cmd+Del to anything but Delete...

I know there are solutions that give you access to key bindings data, things that are really interesting and let you dive into the intricacies of the OS, but I was not really in that mood this morning (I put all the references at the bottom, there is plenty to read and play with, when you have time).

I remembered that there was an app that gives you all the shortcuts available in any given app (at least apps that live into the macOS GUI system, i.e. basically anything that has a real macOS menu at the top of the window, including Java apps like OmegaT, Electron apps like TMXEditor, etc.), the app is "CheatSheet" and can be found here:

https://www.mediaatelier.com/CheatSheet/

Just out of renewed curiosity, I decided to take a peek, just in case...

And there, behold! There is a link to that companion app: "CustomShortcuts" that (also) "works hand in hand with CheatSheet" by allowing you to edit shortcuts directly in the CheatSheet interface, which is pretty neat...

https://www.houdah.com/customShortcuts/

After a quick download and a few authorizations, I can now do what I wanted to do (assign Cmd+Del to Mark as Read, etc.), plus customShortcuts has autocompletion of menu item names, so you don't have to actually check the target application interface and worry about whether "..." is three dots, or an ellipsis… (← this thing).

Et voilà, I've got my workflow fixed now, I can spend the rest of my Sunday with my heart at ease, and here are the references I promised:


References

Post scriptum

You may want to give CheatSheet a "longish" delay before appearing when you hit Cmd, because it gets tiring real quick to have it pop up while you think about the shortcut you actually want to hit while holding Cmd, which really happens all the time...

In 2009, I had put together a similar thing on how to play with keybindings in the shell. It is here:
Bash (command line) shortcuts

Finder selected files, or a scratchpad, in Emacs

# This script a huge improvement on my original script that appeared here
# about 3 years ago: Open a file in your editor of choice.

# This script is a way to either
#   • open in Emacs the files selected in Finder
#    or
#   • open a scratchpad in Emacs when you need to jot down information.

# The script can be adapted to work with any text editor.

# It tests whether Finder was front when the script was launched *and*
# whether it had selected files.
# If either is negative, it opens a scratchpad with a name that's set here.
# Otherwise is opens the files selected in Finder.

# Personal settings:
# Obviously, your Emacs.app file is located in a different place:
set myEmacsAppPath to "/Users/******/Documents/Repositories/emacs/nextstep/"
# This is the name of the empty default Emacs buffer you want to open:
set myScratchBufferName to "turlututu"

# This part is unlikely to change, it assumes that you use the emacsclient
# that corresponds to the selected Emacs.app. And that you run Emacs as a server.
set myEmacsclient to myEmacsAppPath & "Emacs.app/Contents/MacOS/bin/emacsclient"
set myEmacsApp to myEmacsAppPath & "Emacs.app"

# saved by: https://forum.latenightsw.com/t/how-an-applescript-applet-can-get-the-frontmost-application-other-than-itself/2482/7
# This makes sure that this script is not mistaken for the frontmost application.
# The delay works at 0.2 on my machine, 0.1 is not enough.

tell application "System Events"
    tell (first application process whose frontmost is true)
        set frontmost to false
        set visible of it to false
        delay 0.2
    end tell
    set previously_active_app to item 1 of (get name of processes whose frontmost is true and visible is true)
end tell

# Now that we know whether Finder was previously front or not, we can put Emacs to the front.

try
    tell application "System Events" to tell process "Emacs" to set frontmost to true
on error
    tell application myEmacsApp
        activate
        delay 1
    end tell
end try

# The script's main logic is here.

if previously_active_app is "Finder" then
    # If Finder is the active application when the script is launched, either there is
    # or there is no selection.
    try
        # This is the weird part. There are cases when there is no selection but the assignment
        # is not considered an error, hence I test whether item 1 of the selection exists.
        tell application "Finder" to set fileSelection to its selection
        item 1 of fileSelection exists
    on error
        # If item 1 of selection does not exist, there is no selection and the error branches out here.
        # A scratchpad is opened in Emacs.
        set myCommand to myEmacsclient & " -n -e \"(switch-to-buffer \\\"" & myScratchBufferName & "\\\")\""
        do shell script myCommand
        return
    end try
    # Now that we have checked for that non-selection error, we can work on the selection.
    repeat with selectedFile in fileSelection
        set selectedFile to (POSIX path of (selectedFile as alias))
        set myCommand to myEmacsclient & " -n -e \"(find-file " & "\\\"" & selectedFile & "\\\"" & ")\""
        do shell script myCommand
    end repeat
    return
else
    # And if Finder was not frontmost when the script was launched, then we just intended to
    # open a scratchpad in Emacs.
    set myCommand to myEmacsclient & " -n -e \"(switch-to-buffer \\\"" & myScratchBufferName & "\\\")\""
    do shell script myCommand
    return
end if

# Et voilà.
# Now, save the script in the format that corresponds to the way you usually launch scripts.
# I prefer the "myAppScript.app" way so that I can launch my script by calling it from Spotlight.
# I call this one ">Emacs.app".

Popular, if not outdated, posts...

.docx .NET .pptx .sdf .xlsx AASync accented letters Accessibility Accessibility Inspector Alan Kay alignment Apple AppleScript ApplescriptObjC AppleTrans applications Aquamacs Arabic archive Automator backup bash BBEdit Better Call Saul bug Butler C Calculator Calendar Chinese Cocoa Command line CSV CSVConverter database defaults Devon Dictionary DITA DocBook Dock Doxygen EDICT Emacs emacs lisp ergonomics Excel external disk file formats file system File2XLIFF4j Finder Fink Font français Free software FSF Fun Get A Mac git GNU GPL Guido Van Rossum Heartsome Homebrew HTML IceCat Illustrator InDesign input system ITS iWork Japanese Java Java Properties Viewer Java Web Start json keybindings keyboard Keynote killall launchd LISA lisp locale4j localisation MacPorts Mail markdown MARTIF to TBX Converter Maxprograms Mono MS Office NeoOffice Numbers OASIS Ocelot ODF Okapi OLPC OLT OmegaT OnMyCommand oo2po OOXML Open Solaris OpenDocument OpenOffice.org OpenWordFast org-mode OSX Pages PDF PDFPen PlainCalc PO Preview programming python QA Quick Look QuickSilver QuickTime Player Rainbow RAM reggy regular expressions review rsync RTFCleaner Safari Santa Claus scanner Script Debugger Script Editor scripting scripting additions sdf2txt security Services shell shortcuts Skim sleep Smultron Snow Leopard Spaces Spanish spellchecking Spotlight SRX standards StarOffice Stingray Study SubEthaEdit Swordfish System Events System Preferences Tags TBX TBXMaker Terminal text editing TextEdit TextMate TextWrangler The Tool Kit Time Capsule Time Machine tmutil TMX TMX Editor TMXValidator transifex Translate Toolkit translation Transmug troubleshooting TS TTX TXML UI Browser UI scripting Unix VBA vi Virtaal VirtualBox VLC W3C web WebKit WHATWG Windows Wine Word WordFast wordpress writing Xcode XLIFF xml XO xslt YAML ZFS Zip Zotero