I thought this was the way to simulate a click on the red close button at the top left corner of a window:
[NSApp sendActionselector(performClose to:nil from:self];
Oddly, this does not close the window when there is an open unsaved document. (A save dialog appears, and after it is dismissed the window is still open.) Clicking the window's close button does close the window, however.
EDIT: Calling the window's -close method does the trick. Sorry to waste anyone's time.
[NSApp sendActionselector(performClose to:nil from:self];
Oddly, this does not close the window when there is an open unsaved document. (A save dialog appears, and after it is dismissed the window is still open.) Clicking the window's close button does close the window, however.
EDIT: Calling the window's -close method does the trick. Sorry to waste anyone's time.