41{
42 AEAddressDesc addressDesc;
43 const auto bundleIdentifier {
44 [NSRunningApplication runningApplicationWithProcessIdentifier:pid].bundleIdentifier};
45 const auto bundleIdentifierCString {
46 [bundleIdentifier cStringUsingEncoding:NSUTF8StringEncoding]};
47 const auto aeresult {AECreateDesc(typeApplicationBundleID, bundleIdentifierCString,
48 std::strlen(bundleIdentifierCString), &addressDesc)};
49 if (aeresult == noErr) {
50 const auto status {
51 AEDeterminePermissionToAutomateTarget(&addressDesc, typeWildCard, typeWildCard, true)};
52 AEDisposeDesc(&addressDesc);
53 switch (status) {
54 case errAEEventWouldRequireUserConsent:
55 rsj::Log(fmt::format(
"Automation permission pending for {}.", bundleIdentifierCString),
56 std::source_location::current());
57 break;
58 case noErr:
59 rsj::Log(fmt::format(
"Automation permission granted for {}.", bundleIdentifierCString),
60 std::source_location::current());
61 break;
62 case errAEEventNotPermitted:
63 {
64 rsj::Log(fmt::format(
"Automation permission denied for {}.", bundleIdentifierCString),
65 std::source_location::current());
66 const auto title {juce::translate("MIDI2LR needs your authorization to send keystrokes "
67 "to Lightroom")};
68 const auto message {juce::translate(
69 "To authorize MIDI2LR to send keystrokes to Lightroom, please follow these "
70 "steps:\r\n1) Open System Preferences\r\n2) Open Accessibility preferences \r\n3) "
71 "Select \"Accessibility Apps\"\r\n4) Add this application to the approval list")};
72 juce::NativeMessageBox::showMessageBox(juce::AlertWindow::WarningIcon, title, message);
73 break;
74 }
75 case procNotFound:
76 rsj::Log(fmt::format(
"Application not found. Automation permission unknown for {}.",
77 bundleIdentifierCString),
78 std::source_location::current());
79 break;
80 default:
81 rsj::Log(fmt::format(
"Unexpected return value when checking automation permission for {}.",
82 bundleIdentifierCString),
83 std::source_location::current());
84 break;
85 }
86 }
87 else {
88 rsj::Log(fmt::format(
"AECreateDesc returned error {}.", aeresult),
89 std::source_location::current());
90 }
91}
void Log(const juce::String &info, const std::source_location &location=std::source_location::current()) noexcept
Definition Misc.cpp:112