Instance Method


Sent by Cocoa’s built-in scripting support during execution of get or set script commands to find out if the delegate can handle operations on the specified key-value key.


- (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key;



The app object associated with the delegate.


The key to be handled.

Return Value

YES if your delegate handles the key or NO if it does not.


The method should return YES if the delegate for the app sender handles the key specified by key, which means it can get or set the scriptable property or element that corresponds to that key. The app implements methods for each of the keys that it handles, where the method name matches the key.

For example, a scriptable app that doesn’t use Cocoa’s document-based app architecture can implement this method to supply its own document ordering. Such an app might want to do this because the standard app delegate expects to work with a document-based app. The TextEdit app (whose source is distributed with macOS developer tools) provides the following implementation:

return [key isEqualToString:@"orderedDocuments"];

TextEdit then implements the orderedDocuments method in its controller class to return an ordered list of documents. An app with its own window ordering might add a test for the key orderedWindows so that its delegate can provide its own version of orderedWindows.

See Also


- endModalSession:

Finishes a modal session.

- endSheet:

Ends a document modal session by specifying the sheet window.

- endSheet:returnCode:

Ends a document modal session by specifying the sheet window.