Xcode: multiple key bindings per function

12

2

In Xcode I'd like the ability to set up several key bindings for the same function. For example, I'd like the step over function to be mapped to both F6 and F16. I don't see a way to do this from Xcode itself.

Does anyone know a way to do this? (I'm using Xcode 4.2.1)

joseph.hainline

Posted 2012-02-23T16:31:24.843

Reputation: 1 903

Answers

4

I researched a bit on your question. Natively it seems that there is no way to specify multiple shortcuts for the same function -- I've tried to open ~/Library/Prefences/com.apple.dt.Xcode.plist file and manually edit the NSUserKeyEquivalents adding a duplicate element for Step Over, but upon Xcode startup the duplicate element was automatically deleted (it makes sense since the wrapping element is named <dict>).

I've found a rough way to set the second shortcut, inspired by this article. Instructions are for OS X 10.8:

  1. in System Preferences, under Accessibility enable Enable access for assistive devices;
  2. download and install Quicksilver, a free launcher for OS X;
  3. save the following AppleScript to Documents folder (for example with name StepOver.scpt) -- be sure to copy also the ¬ characters. This scripts activates Xcode and selects the Step Over function.

    tell application "Xcode"
        activate
    end tell
    
    tell application "System Events" ¬
    to tell process "Xcode" ¬
    to click menu item "Step Over" ¬
    of menu "Debug" of menu item "Debug" ¬
    of menu "Product" of menu bar item "Product" ¬
    of menu bar 1
    
  4. launch QuickSilver and navigate to Preferences -> Triggers -> Custom triggers

  5. create a new trigger, in which you open StepOver.scpt script using the hot key you want (in the screenshot I've used F10). In the Scope tab you can specify that the trigger only works in Xcode. trigger example
  6. at this point the additional shortcut should work, I've built a basic console C++ application in Xcode and I could step over using using F6 (as "standard" shortcut) and F10 (as additional shortcut configured with QuickSilver).

As a final note, you could also evaluate software to create macros like Keyboard Maestro -- it's commercial and I haven't tried it.

edymtt

Posted 2012-02-23T16:31:24.843

Reputation: 551

1tell application "System Events" to tell process "Xcode" to click menu item "Step Over" of menu "Debug" of menu item "Debug" of menu "Product" of menu bar item "Product" of menu bar 1 work just as well without additional set-up code. – Daniel Beck – 2012-12-30T20:08:13.843

Thanks @DanielBeck, I'm not familiar with AppleScript. I've edited my answer and simplified this part using with your suggestion -- now the code is more readable. – edymtt – 2012-12-30T20:17:33.420

This works! It's a little complicated to set up, but only took about 2 minutes. I think I like Quicksilver as a tool I could use for a few other things. Thanks for figuring this out! – joseph.hainline – 2012-12-31T02:57:57.783

0

I do this with Keyboard Maestro. You can assign a command to one or more applications or global. It's a fantastic piece of software I can't live without. It's the best piece of software I've ever bought. You would be shocked to see how many key bindings I have.

Attached is an image where I map a hotkey to a menu item. Ignore the action grayed-out in the image. It starts off with "Execute Macro". Menu Select is the action you want

Mike Retondo

Posted 2012-02-23T16:31:24.843

Reputation: 1

0

You can use the keyboard shortcut mapper for this process see attached image.

enter image description here

I hope this helps you

Justin Erswell

Posted 2012-02-23T16:31:24.843

Reputation: 101

I was so hopeful this would work! When I tried it, only the F16 keyboard shortcut worked, and F6 no longer worked from within XCode (it just made the error sound instead of doing anything). The system level mappings seem to overwrite the app level mappings. I'm using XCode 4.5.2 and OSX 10.8.2. Did this work for you, and what versions are you using? – joseph.hainline – 2012-12-18T03:42:38.060

Hi there sorry it wasn't complete;y correct use ctrl+f6 this will work alongside f16 that is the best I think you can get my apologies. – Justin Erswell – 2012-12-18T08:37:52.043

Thanks for the attempt, but I guess what I'm looking for is simply not possible. Ctrl+F6 is a different command than F6. When I map at the system level, it just overrides the app level. I'm really trying to get two keys mapped at the same time to the same function. – joseph.hainline – 2012-12-19T03:14:55.923