Cmd – click. The subtle secret of Mac OS X.

Cocoa, General

It seems that a lot of people don’t know how cmd click works in a lot of Mac OS X Cocoa applications. To put it simply, Cmd-clicking on a non key window (or application for that matter) will act like a normal click without making the window key! This is really cool for testing UI things while debugging or testing for memory leaks.

Here is how I use this technique while debugging:
1. I’m debugging my application with Xcode. Inside of Xcode I have a “hot” breakpoint that I don’t want to enable, since enabling it will make Xcode key, and the key/focus switching will hit the breakpoint at the wrong time.
2. Because of this, I keep my application key, and Cmd-click on the title bar in Xcode to move the window to where I can see the breakpoint.
3. Then, I Cmd-click the breakpoint, enabling it without setting the window key and never leaving focus from my application that i want to debug.
4. Now, I perform the operation that invokes the breakpoint and debug away.

Sure, you could do this by figuring out how many times the breakpoint was hit, and in gdb ignore the breakpoint for X times, but sometimes that is a pain to do.

I also use this technique while trying to find memory leaks with Object Alloc. Frequently, focus switching causes numerous allocations, and by Cmd-clicking the “Mark” button in Object Alloc I can prevent those allocations from happening.

Note that cmd click doesn’t work 100% correctly with certain components. For instance, NSTableView won’t change the selected item unless it is key (note that that bug will be fixed).

–corbin



Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Subscribe to new posts:

You'll get an email whenever a I publish a new post to my blog and nothing more. -- Corbin

As an Amazon Associate I earn from qualifying purchases.

(c) 2008-2024 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

65 queries. 0.134 seconds.

Log in