How to let user customize menu keyequivalents - cocoa

In my cocoa OSX app I have defined a main menu with key equivalents using interface builder. Occasionally I get user requests for being able to customize these key equivalents. I know users can (re-)define shortcuts for an app via Mac OSX System Preferences | Keyboard | Shortcuts, but this is rather cumbersome if you'd want to redefine many shortcuts. What is the common way of showing all available actions (menu items) and letting a user customize the associated key equivalents? I could brew my own, but would like to know if there are solutions ready available. Thanks in advance,

I use SRRecorder, and it works very well, and sounds like it'll do what you are looking for.
https://github.com/Kentzo/ShortcutRecorder

Related

Collecting keyboard shortcuts for menu items of another application

I'm writing an application that allows access to other applications' menu items via the accessibility framework. I have no problem obtaining the list of menus, their menu items, etc..
As far as I can see, however, the accessibility framework does not give access to the keyboard shortcuts for each item.
More concretely, if my app presents the Finder's File -> New Finder Window menu item, I would like to annotate it on screen with Command-N, so the user can learn the shortcuts by heart.
At the moment I see no way of getting that information. If not via the AXUIElement accessibility framework, how else can one get that info?
Any help would be much appreciated.
I have managed to find AXMenuItemCmdChar and associated AXUIElement attributes that actually have the information I'm after. Unfortunately, the Swift framework that I use to bridge the C-level Carbon accessibility APIs defines a convenient enum for all the attributes.. only it's not quite all the attributes :-(

Global list of assigned keyboard shortcuts osx?

I favor keyboard shortcuts over mouse actions so I'm heavily using keyboard shortcuts with all kinds of applications. Every now and then I'm running into a situation where I assign a keyboard shortcut that has already been used in a different app. Not all apps show warnings when you re-use a combination that has already been used.
Also, since I tend to forget some of the lesser used combinations, it would be nice to find out what has been assigned where.
System Preferences doesn't list all of them, but since my Mac responds to them, there must be some way to get a global list of all assigned keyboard shortcuts.
Does anyone know of a command/script/application that displays them all?
What you want may not be possible. Consider the method by which a application specific system-wide shortcuts may be implemented: event taps. An application can do whatever it wants with an event and never actually register the event with the system. Thus, no application could be written to identify every possible event!
Here is an app that does almost what you want:
http://www.ergonis.com/products/keycue/
It even updates its list when shortcuts are changed.
You can download a list of additional system-wide shortcuts from their site that includes keys not listed anywhere else. But it doesn't show shortcuts for continuously active applications such as Evernote.
Further, you can query and modify hotkeys programmatically:
http://www.theregister.co.uk/2009/02/24/hotkeys_framework2/
(but it still won't know about event taps)
This list of all system shortcuts from Apple is also useful:
http://support.apple.com/kb/HT1343

How do I allow ⌘V into NSTextField without having a Menu?

I've removed the menu from my cocoa app, all of the interaction should happen from within a status item, that links to a menu, that links to different NSPanels. But this seems to have removed the ability to ⌘C or ⌘V within a NSTextField. Is there a way to add this back without having to have a standard menu included with my app?
Even if your app is a faceless background app, so it never shows a menu bar, you should still have a full main menu because that's what provides all of the default actions (and enables the user to redefine the key commands if they so choose). If you remove the main menu, you have to reimplement everything in it, including anything Apple adds in the future, in code.
And I'd especially warn you against trying to handle keyboard shortcuts yourself. That's damned tricky. A lot of applications get it wrong, causing us Dvorak users (among others) to curse their developers.
I assume you can just implement the actions originally connected to the menu items in a keyDown event. Check out this page for details: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html
Just have it respond to cmd-v with paste:, and cmd-C with copy:
Edit: Though I have to agree with Peter, you really should have a main menu...

Add custom menu items to the Finder context menu

How do I add custom menu items to the context menu for files in Finder?
Unfortunately, most of the information out on the Internet and on Stack Overflow doesn't work in 10.6 or are too limited. Automator, for example, doesn't allow you to create items dynamically or create submenus.
I know it's still possible to do this sort of thing because Dropbox and FolderGlance both do similar things. Does anyone know how they implemented this?
Thanks.
For what it's worth, Dropbox now uses mach_star for code injection. Obviously this is a fragile solution. If you look through their version history, many of their updates are to fix finder integration.
In macOS 10.10+, Finder Sync Extensions can be used to add items to the Finder context menu. This is how modern versions of Dropbox and similar apps customize the right-click menu.
For those just seeking to use the functionality, not develop their own app extension, I've released a Mac app that allows for arbitrary customization of a Finder Sync Extension:
Service Station - Mac App Store
I downloaded FolderGlance and it appears to use an osax (Scripting Addition) bundle to inject code into the Finder process. This is definitely fragile and unsupported.
As far as I am aware the only legit way to add items to the Finder contextual menu is to create a Service, but that doesn't solve your problem.
Up to to the OS X 10.9.x only injecting code to Finder process via mach_inject was a solution (and even Dropbox did that).
However since 10.10 there are Finder plugins, which can customize context menus, add buttons to Toolbar and put overlays over file icons.
They used CFPlugIn to add their menu items.
More on it here:
http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFPlugInRef/Reference/reference.html

intercepting keystrokes in OSX

I'd like to be able to listen to keystrokes systemwide in OSX to implement an utility like AHK on windows (the shortcuts part of AHK anyway), recognizing not only simply combinations of keys, but even more complex things like sequences etc..
I need someone to point me... where to start? How to listen to keybard events system wide? Maybe there's something in the cocoa framework or that's not where to look for?
Quartz event taps. Look up CGEventTapCreate in the Xcode doc viewer to get started. Note that the user must check "Enable access for assistive devices" in the Universal Access preference panel before you'll be able to monitor keyboard events. (And even then you won't see keystrokes within password fields.)

Resources