1
votes

How can I setup a callback to be triggered when the yellow window iconize/minimize button is clicked on OSX?

What I'm aiming for is to intercept the minimize button systemwide so that windows can be hidden (as in CMD-h) instead of iconized/minimized. For that I'd also need a hide-window method if such a function exists.

EDIT

Using the yellow minimize button in Mac applications causes the app to disappear. I have it set so that no extra icon is created in the dock (preference setting: 'Minimize windows into application icon'). When Alt-TAB is later used to restore the app, the window is not restored from the icon although the app itself does become active. This behavior is different from how CMD-h works. Although I have used a Mac for years I continually find the consequent uselessness of CMD-TAB irritating.

1

1 Answers

0
votes

I'm not sure why you want to change the normal behavior that users expect. Command H hides an application's UI as a whole. Command M or ( if set in system preferences ) double clicking a title bar will minimize a window.

Users can also customize keyboard shortcuts in system preferences.

The controls are set in the responder chain so that these keyboard shortcuts are sent up the responder chain and the first window in line responds.

They are implemented in NSWindow and can be overridden in many places. NSApplication subclasses are one place as are NSApplicationDelegate subclasses. Any window delegate could also do something different as well.

You should look at all of these classes and their programming guides as well as the responder chain and NSEvent to understand this more.

You have a lot of options.

Based on the Edit to the question, the answer is mostly unchanged. If you want to do this with cocoa, look at the above classes. There are NSNotifications you can observe and respond to when your app becomes active and inactive.

If you want to control other apps, you will need to look at NSWorkSpace and NSRunningApplication but also AppleScript and NSAppleScript.