From 727dc9879454c0aea3b2cf4aecbd54d95d8ae45b Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 8 Jun 2019 17:46:01 +0200 Subject: MacGui: fix queue sleep and shutdown on 10.14 and under sandbox. --- macosx/HBQueueController.m | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'macosx/HBQueueController.m') diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m index bd8564ded..87d0ceefe 100644 --- a/macosx/HBQueueController.m +++ b/macosx/HBQueueController.m @@ -1073,7 +1073,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; // Sleep NSDictionary *errorDict; NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource: - @"tell application \"Finder\" to sleep"]; + @"tell application \"System Events\" to sleep"]; [scriptObject executeAndReturnError: &errorDict]; } // If Shutdown has been selected @@ -1081,7 +1081,7 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { // Shut Down NSDictionary *errorDict; - NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:@"tell application \"Finder\" to shut down"]; + NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to shut down"]; [scriptObject executeAndReturnError: &errorDict]; } } @@ -1219,6 +1219,8 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { [self.delegate showPreferencesWindow:nil]; } + + [self promptForAppleEventAuthorization]; } else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"HBAlertWhenDone"] == HBDoneActionShutDown) { @@ -1237,6 +1239,17 @@ static void *HBControllerQueueCoreContext = &HBControllerQueueCoreContext; { [self.delegate showPreferencesWindow:nil]; } + + [self promptForAppleEventAuthorization]; + } +} + +- (void)promptForAppleEventAuthorization +{ + HBPrivacyConsentState result = [HBUtilities determinePermissionToAutomateTarget:@"com.apple.systemevents" promptIfNeeded:YES]; + if (result != HBPrivacyConsentStateGranted) + { + [HBUtilities writeToActivityLog:"Failed to get permission to automate system events"]; } } -- cgit v1.2.3