Keyboard tricks from a macOS app dev
notes.alinpanaitiu.com
notes.alinpanaitiu.com
Apple has a pretty exhaustive list of so-called document shortcuts that I find particularly useful: https://support.apple.com/en-us/HT201236#text
Ctrl+A and Ctrl+E in particular to jump to the beginning and end of a line are a pair that I use dozens of times per day.
Same with Opt+Delete to delete the previous word.
I use Opt+Left Arrow and Opt+Right Arrow to move the cursor back and forward by whole words so often that I didn't even think about including it in here until I unconsciously used it while editing text.
Also:
Cmd+Space brings up Spotlight and is a great way to launch apps and open documents.
I've used SizeUp for well over a decade to rearrange my Mac's open windows. It's literally the first app I install when I get a new computer. https://www.irradiatedsoftware.com/sizeup/
https://en.wikipedia.org/wiki/GNU_Readline
https://github.com/chzyer/readline/blob/master/doc/shortcut....
Sometimes I use an iPad plus Bluetooth keyboard for writing.
What's annoying is that keyboard shortcuts mostly work in apps, but are sometimes buggy, because I think they're so rarely tested.
- it doesn't make sense to have a/e as beginning/end, there is a symmetry in the commands, but there is no symmetry in the a/e keybindings, they are on different rows
- likewise, it doesn't make sense to use the less convenient ⌃ for such a frequent command (and this is also the rightful criticism of all the bad Emacs pinky defaults)
For example, you could use right ⌘ (a thumb key) as your text movement key (or even Space), then you have home keys - JKL; for cursor movements and
- DF for your word movements (instead of having to move your whole hand to ⌥◀/▶)
- A/⇧A for line start/end movements or maybe A/G if it's frequent enough to not warrant using ⇧
And then that would match your text editor keybinds, so you don't have to waste time remembering platform-specific keys.And re. those other apps - it's better to rebind them all (or, rather, use a tool to have the keybinds work in all of them) as well to use something good rather that stick with the bad just because someone lacked good design chops in the past
Spotlight usually works for most of my needs as well.
It’s frustrating when an app overwrites built in shortcuts like in Intellij on Mac, searching for shortcuts in the menu bar search doesn’t allow opt-delete if I remember correctly.
Speaking of menu bar search… one of my favorite commands is opt-shift-/ to search available commands in the menu bar of an app.
The more I got familiar with MacOS, the more I realized all those feature pictures ople praise MacOS for are just workarounds / copies from other systems, and (even power-) users just aren't familiar with other systems hence their amaze.
The inconsistencies that come with intermixing ctrl-option-command are just mind blowing. Even Windows got this right by making the Windows key control window manager specific actions.
By the time I’d started working as a dev fulltime where those keys might’ve been useful, laptops had taken over and my work machine was a MacBook Air which wasn’t large enough to fit those keys even if they’d wanted to, and so I learned the built in macOS text nav shortcuts. They were never a workaround for me because I’d never used the home/end/etc cluster in the first place.
Even today when using Windows or Linux it’s with a 60/65% keyboard without those keys because that’s what’s comfortable. Reaching over to hit home/end on a larger keyboard would feel odd with how far removed it is from the rest of the board.
Those keys are not lacking, but on laptop keyboards they are hidden behind the fn+arrow keys. But they also are not workarounds or replacements for those keys. On macOS Home and End scroll the document to the beginning or end, not the cursor to the beginning or end of the line. That can be done with cmd-arrow.
Having used Linux Pop OS for many years, I've grown accustomed to the intuitive and powerful tiling window manager and keyboard navigation shortcuts it offers. I'm struggling to find a comparable solution on the macOS platform.
But you can get very far to an automated tiling WM and keyboard navigation even without disabling SIP.
In later versions they added keyboard access, but it still feels like it was done as a bare-minimum concession and not originally planned.
It is kind of evolution, just for computers.
Macs early developed good pointing devices and as a result many keyboard related aspects can afford to be somewhere between weird and crazy.
Bonus for Mac people insisting everything is fine.
And I still consider getting a MacBook Pro next month, Windows PCs are that bad even with WSL :-/
Edit: at least these days, fn and ctrl can finally be remapped and CMD-tab can be fixed so it works consistently between two Firefox (or two Safari) windows, an IDE and Finder. It used to be that I would have to CMD-tab to the Firefox group, then CMD-| to get to the correct browser window and it was one of the things that truly messed up my workdays the last time I used Mac back in 2012. (No dedicated home/end buttons and every app seemingly being free to choose what shortcut they would use for it was probably the most painful one though.)
In KDE it's pretty much a joke every time I have to save-as. Can't even get through that filesystem menu without a mouse unless it supports <ctrl>-l. Dolphin is slightly better, especially if you enable the console pane to make it easier to switch to the command line, but it's still way behind Apple's finder from 1999.
How do you open the menus and browse through them to find and select the option you want?
I think you would be surprised at just how powerful the keyboard subsystem in osx is and how malleable it is with some programs or even just editing the plist shortcuts. every menu item in any application can be given a per app or universal shortcut in `system preferences | keyboard | shortcuts | app shortcuts`
You can also use a thing like hammerspoon to do whatever you can imagine basically too... i have a few things for window manipulations via hammerspoon.
You can set up very complex keyboard re-mappings/shortcuts using something like karabiner elements.
you can also change the keyboard access to be navigable via tab in keyboard settings too.
and you can access the menu via ctrl-f2 by default. those settings are changeable too via the keyboard preference pane.
i think you'd be surprised at how much apple cares about accessibility so keyboard nav is not just a power user thing.
At the end of the day I think apple put a lot of thought into the UI and i'd feel pretty stymied going back to windows.(though now the power utilities finally let you remap the windows key to something more useful like ctrl.
Even with the awesomeness of Karabiner Elements there are some unfortunate limitations
But yeah, I'd be surprised if it were a powerful system, that's so rare in the keyboard land...
Also, how is it user friendly to require users to retype the full menu taxonomy???
there's also applescript that can do a lot of other things too. I dislike the language but it's fairly powerful too.
[0] http://www.hammerspoon.org/docs/hs.application.html#getMenuI...
By the way, what would I do with this menu info, is there another function to permanently rebind a given menu item?
I was just pointing a few fundamental flaws in this "surprisingly powerful" system
Also, this brings confusion between the key shown in the menu and the key that is used to activate it, is the Mac ecosystem powerful enough to fix this little usability snag?
no clue, I don't use automator, but from what I understand of applescript and automator this should be completely possible. For what it's worth I use Hammerspoon like the other commentor and it's by far the best system I've seen for any OS. Also the more people that use it the better it gets so I highly recommend it.
>Also, how is it user friendly to require users to retype the full menu taxonomy???
I mean... you're able to change any arbitrary menu item in any program that exists. That's extremely powerful. I don't really know how you would make it make it any more user friendly.
> any arbitrary menu item in any program that exists
That's false
> I don't really know how you would make it make it any more user friendly.
Just read my comment, it tells you exactly how to make it user friendly. And it's easy to come up with a few more ideas
In what way?
> Just read my comment, it tells you exactly how to make it user friendly.
I’ve reread all of your comments in this thread and find no such thing.
That doesn’t mean adopting everything or abandoning everything, just try to be flexible and try some different things out. Just because it is different doesn’t mean it is broken.
For window management there are dozens (at least) third party tools that add features like snap window. Try some out to see what you like. Rectangle, Magnet, Moom, BetterSnapTool come to mind but here are others.
(it's not Apple's strong suit, but there is an app for tha™)
For example, AFAIK, there's no way to eliminate the animation that's triggered when switching spaces/virtual desktops.
(also, afaik https://github.com/koekeishiya/yabai allows you to eliminate the animation completely)
On macOS the thing that drives me insane is that the many-finger swipe to switch desktops won’t focus the target window until the animation is totally done (like 0.7s after starting). I wish it works like cmd+tab which changes focus instantly. Apart from that I guess I’m not that bothered because I mostly just full screen things. Emacs and iterm2 can do their own tiling of windows.
The only disadvantage is that there is no way to "peek" the previous desktop like you can with the built in swipes.
For almost everything else there's a standardized system-wide shortcut (including the ancient ones like Ctrl+a/e for text).
If there isn't a shortcut, but the app exposes the action in a menu, you can assign a custom shortcut from keyboard settings.
MacOS has traditionally been very friendly to keyboard navigation. Well, until somewhat recently when mobile-only/mobile-first devs started just slapping Catalyst on and calling it a day. Even Apple's own apps suffer from this.
The standardized menu system is underrated, IMO.
Setting aside preferences for the menubar being global vs. being attached to app windows, the fact that it's system-owned makes features like this possible. Apple was able to implement custom keybinds for menu items in arbitrary apps because they know that 99.9% of apps use the system menubar. This would be next to impossible on Windows where menubar implementations are disparate and numerous (even within first party apps), and while something similar could be patched together on Linux, it'd only work on some (mostly Qt) apps since GTK has mostly abandoned menus altogether.
This also enables the menu search in macOS Help menus to work, which is underused despite being basically a command palette for every app.
I have keyboard shortcuts well in muscle memory now for left/right third/half/two-thirds, and all four corners at a quarter of screen, and full screen. I find that meets 90% of my needs.
Left/right two-thirds is my go-to when coding on 14”. VSCode on the left, Safari on the right. Both big enough to work well, but both leave enough of the other visible to be useful.
Nice little app, costs some reasonable amount of money as a one-off purchase.
But then you can mostly get by with a finder alternative
It's one of the first things I always need. It started coming from Linux with a similar experience to you.
----
A big shortcut for me is cmd+shift+/
It allows searching on all submenus. So when I'm working on an IDE for example, it's how I find those obscure options I know are there but I don't use frequently enough to remember the shortcut.
I am quite frequently on MacOS, and I use Yabai[0] and skhd[1], managed with Nix-Darwin[2] for tiling windows and custom keyboard shortcuts. With how I make my Linux and MacOS builds look and feel identical it's pretty easy for me to forget when I'm on one vs the other.
For anyone curious, here's my repository for deploying my configs[3]. It's awesome to have one source of truth for managing NixOS servers and workstations, MacOS workstations, and other Linux workstations with Nix installed.
[0] https://github.com/koekeishiya/yabai
[1] https://github.com/koekeishiya/skhd
Otherwise go with whats been suggested by others
Whenever advanced keyboard shortcuts are under discussion, I’m reminded of something I read, I think by Bruce Tognazzini, on an early Apple study of keyboard vs. mouse. They had set up the usual usability test—run through these common spreadsheet tasks or whatever—and compared skilled users exclusively on mouse with equally skilled users issuing keyboard commands via shortcut. Maybe they swapped them back and forth on the modes, I don’t recall.
When the experiment was over, the mouse and keyboard users agreed: Shortcuts were faster, switching hands to the mouse and issuing commands via the cursor was slower. But the actual measured results showed no significant difference. Tog speculated that there’s some deep perceptual circuitry that’s tuned to notice the cost of mode-switching but submerge into the subconscious the cost of recall.
EDIT: I'm sure he's referenced it a dozen times in a dozen places, but here's a version of Tog's analysis that's roughly what I remember:
https://www.asktog.com/TOI/toi06KeyboardVMouse1.html
We’ve done a cool $50 million of R & D on the Apple Human Interface. We discovered, among other things, two pertinent facts:
- Test subjects consistently report that keyboarding is faster than mousing.
- The stopwatch consistently proves mousing is faster than keyboarding.
This contradiction between user-experience and reality apparently forms the basis for many user/developers’ belief that the keyboard is faster.
People new to the mouse find the process of acquiring it every time they want to do anything other than type to be incredibly time-wasting. And therein lies the very advantage of the mouse: it is boring to find it because the two-second search does not require high-level cognitive engagement.
It takes two seconds to decide upon which special-function key to press. Deciding among abstract symbols is a high-level cognitive function. Not only is this decision not boring, the user actually experiences amnesia! Real amnesia! The time-slice spent making the decision simply ceases to exist.
I can imagine that moving the mouse to open an app from the macOS dock is about the same speed as using the Cmd+Space or some shortcut.
I can't imagine using the mouse to go to the start/end of line is quicker than using an easy to reach keyboard shortcut to do so.
I'd also wonder about differences in general computing literacy/etc. between 1989 and now. -- I'm not sure "people new to the mouse" describes a meaningful subset of professional computer users these days.
It's a counter-intuitive conclusion because it's a wrong conclusion.
And to me it looks like they only focused on the first case because of sentences like this:
> It takes two seconds to decide upon which special-function key to press
Yes, I can definitely believe that I wouldn't be faster than a mouse user if I had to select text with a keyboard in notepad or press Ctrl-Alt-whatever to do simple tasks. But good luck beating a proficient Vim user at anything that has to do with cursor movements, search/replace or repetitive steps - watch a competitive coder use Vim and see how often it takes them "two seconds to decide" to do anything.
I think overall people have a decent intuition about what the more efficient way to control an application is. I frequently use the mouse/touchpad too, because in many GUIs it's simply faster and you can feel that even when you start out focused on the keyboard. Often users switch between window management and using graphical applications, and in those cases leaving the hand on the mouse is the more convenient approach.
And lastly - does it even matter? When someone perceives a certain approach to be faster or smoother, then why not let them? In almost all cases the speed difference doesn't matter.
Not mentioned are the text navigation shortcuts that have been built into macOS for a similarly long period of time. They work in any text field in nearly every app (with exception to a few oddball apps that are usually built with "game engine style" UI frameworks), and come in both control-based emacs style and Apple style flavors[0]. I use these constantly and they work exceptionally well for smaller keyboards (e.g. 60% or HHKB).
But Raycast works differently in that:
- it has dynamic replacements (see the video where I use ,td to type today's date for example)
- can place cursor somewhere inside the replacement
- makes it easy to add new snippets (Cmd-S on copied text)
- is a lot faster in general and can work inside words as wellThat single feature alone is worth the app to me.
I came from i3 with 8 predefined windows, but the simplicity of rcmd is really amazing.
Using multiple spaces on macOS is nowhere as easy as on i3.
I want to collect all my notes on this and publish a series of articles in 1-2 months. Glad to see others interested!
What are your favorite shortcuts?
The fact that this completely standard binding has been broken in a crucial macOS app for 5 months basically tells me that Apple does not care about the "Emacs-style" shortcuts in macOS.
I haven’t used it for a couple of years, so it may be flakey, but worth a shot.
That's why I eventually settled for the rcmd-lcmd sequence, it's much more convenient for me and doesn't clash with my other bindings.
But the one key I use the most is assigning “`” key as the back button. You keep your hand on that key while surfing web or any app that has a back navigation, it’s just so much better than clicking or remembering each apps back shortcut.
If you really need to type ` then you assign fn-` it’s really rarely used
Sure there are generally (sometimes better) alternatives in those but backticks are pretty common for me.
Although the only thing I really need Karabiner for is remapping caps lock to a custom-defined "hyper" key (something odd combination of right and left shift, alt, command, etc) that everything else can use.
I know Raycast is getting a lot of attention right now but isn’t this a VC-backed SaaS? How do people feel about inviting them on to their desktop - aren’t you worried about the inevitable other shoe dropping?
But I really like what Raycast has become for the rest of the stuff. For example the calculator is just amazing, it replaced Soulver and Alfred completely for me, doing the currency and datetime operations a lot more intuitively.
And for now, Raycast is a full fledged app whose binary I own completely and works offline. So even if the Raycast company had problems, I can keep using the current binary forever. There's not much functionality that would go extinct with OS updates.
I'd say it's worth the risk.
FuzzyKey would be really awesome, it's indeed an issue to remember all the complex conditional rebinds (and even in which app you've made it)
Would be nice if you could have an easily accessible cheat sheet and also press any combo in an app and let it tell you where and how it was defined
I do use the MacOS text expansion system for my name and a few other items, but what it lacks is (1) I cannot use hyperlinked text in the expanded snippet, and (2) it requires me to remember an incantation for each expansion (I want to be able to look at a list of items and pick the one I want.
Does anyone know of a tool that can do this? I don't mind paying, but free is always appreciated!
It can do the incantation thingie, but it also allows binding a hotkey to showing a list of your snippets, searching through them, and inserting them with Enter.
It can also do hyperlinks, bold, italic, if the app you're typing into supports rich text. Example: https://shots.panaitiu.com/gw50Zdcm
EDIT: Looks like for snippets, it requires a key command to get Raycast to appear, then you have to say Search Snippets, then you have to type your search string, then you have to select the desired snippet. Is it really this many steps? My old workflow was shift-cmd-v, choose the desired snippet via arrow keys, hit return. With muscle memory, this ended up taking less than 4 seconds for most snippets.
I rarely if ever see that main search UI, I have hotkeys for all my favorite workflows.
The Shelf plug-in also very handy along similar lines.
Specifically I am interested in fixes for Outlook, which overrides the default text editing cursor movement commands with its own shortcuts.
These utilities are only able to detect which app is running, but no what's going on inside the app
Is there any online resource that you would recommend to help her refine her skills?
TL;DR: Capslock is Hyper key when held (Escape when pressed). Then I have hyperkey sublayers to allow for having essentially infinite commands: Capslock + O ("Open") + S ("Slack"), Capslock + S ("System") + U = Volume Up, J = Volume Down, etc.
I get the impression OP is a junior dev.
https://github.com/peterklijn/hammerspoon-shiftit
I like to move windows around with just my left hand, which doesn't work if you use the right command key.
Instead you can use left_alt + left_command together
The full list of commands I use with the ShiftIt spoon:
spoon.ShiftIt:bindHotkeys({
left = {{ 'alt', 'cmd' }, 'z' },
right = {{ 'alt', 'cmd' }, 'x' },
up = {{ 'alt', 'cmd' }, 'q' },
down = {{ 'alt', 'cmd' }, 'a' },
resizeIn = {{ 'alt', 'cmd' }, '-' },
resizeOut = {{ 'alt', 'cmd' }, '=' },
toggleZoom = {{ 'alt', 'cmd' }, 'f' },
upleft = {{ 'alt', 'cmd' }, '1' },
upright = {{ 'alt', 'cmd' }, '2' },
botleft = {{ 'alt', 'cmd' }, '3' },
botright = {{ 'alt', 'cmd' }, '4' }
})
Alt = Option on MacTo move a window to the center of the screen with Hammerspoon:
hs.hotkey.bind({"cmd", "alt"}, "s", function()
-- size focused window to middle third of display
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 3)
f.y = max.y
f.w = max.w / 3
f.h = max.h
win:setFrame(f)
end)
To move a window to the next/previous screen (external display): -- move window to next screen
-- bind hotkey
hs.hotkey.bind({'alt', 'ctrl', 'cmd'}, ']', function()
-- get the focused window
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end)
-- move window to previous screen
-- bind hotkey
hs.hotkey.bind({'alt', 'ctrl', 'cmd'}, '[', function()
-- get the focused window
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the previous screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:previous(), true, 0)
end)
I use left alt and left command together for one handed shortcuts.I use Quicksilver to set triggers to open apps with left_alt + "key"