title: How to programmatically dismiss an NSAlert run modal for window
body: <p>Thread 1 runs a modal alert:</p>
  
  <pre><code>- (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
  {
  [sheet orderOut:self];
  };
  
  
  -(void)newAlert
  {
  currentAlert=[NSAlert alertWithMessageText:@"Switch drives!" defaultButton:@"Cancel sync" alternateButton:nil otherButton:nil informativeTextWithFormat:@"Please switch disks: %@",reason,nil];
  [currentAlert setDelegate:self];
  [currentAlert beginSheetModalForWindow:self.window completionHandler:^(NSInteger returnCode)
              {
                  mustStop=TRUE;
              }];
  
  }     
  </code></pre>
  
  <p>Elsewhere, on another thread I want to dismiss the alert, but this doesn't work:</p>
  
  <pre><code>[NSApp endSheet:[self window]];
  </code></pre>
  
  <p>It does not work.</p>