Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect OSX admin password prompt?

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?

like image 775
JohnDvorak Avatar asked Jul 13 '16 12:07

JohnDvorak


1 Answers

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
like image 196
Chester Taylor Avatar answered Sep 23 '22 15:09

Chester Taylor