I'm trying to (programmatically) detect the OSX administrator password prompt that appears when changing system security settings. Ideally the solutions would work for C++ or Objective-C. I've looked at various NSDistributedNotificationCenters
that provide OS notifications, but none of them seem to be specific to the password prompt. I've tried registering for all notifications that the OS can provide, but these notifications seem to stop once I've entered the System Preferences window.
I've also looked into the SFAuthorizationPlugin
concept, but it seems like that's more for logging into the system from a cold boot.
I know it is possible, as I've seen other applications detect the password prompt and display something on the screen whenever it appears.
So how can I programmatically detect the OSX administrator password prompt?
You can listen for SecurityAgent notifications from the workspace.
Subscribe to application activation notifications like so:
@interface notificationHandler: NSObject {}
@end
@implementation notificationHandler
-(id)init
{
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector :@selector(handleNotification)
name :NSWorkspaceDidActivateApplicationNotification
object :nil];
} // init
-(void)handleNotification:(NSNotification *) notification
{
NSDictionary info = [notification userInfo];
NSString *appName = [[info objectForKey:NSWorkspaceApplicationKey] localizedName];
if ([appName isEqualToString:@"SecurityAgent"]) {
// You have found the administrator password prompt!
}
} // handleNotification
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With