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(FMT_STRING(
"Automation permission pending for {}."),
56 bundleIdentifierCString),
57 std::source_location::current());
58 break;
59 case noErr:
60 rsj::Log(fmt::format(FMT_STRING(
"Automation permission granted for {}."),
61 bundleIdentifierCString),
62 std::source_location::current());
63 break;
64 case errAEEventNotPermitted:
65 {
66 rsj::Log(fmt::format(FMT_STRING(
"Automation permission denied for {}."),
67 bundleIdentifierCString),
68 std::source_location::current());
69 const auto title {juce::translate("MIDI2LR needs your authorization to send keystrokes "
70 "to Lightroom")};
71 const auto message {juce::translate(
72 "To authorize MIDI2LR to send keystrokes to Lightroom, please follow these "
73 "steps:\r\n1) Open System Preferences\r\n2) Open Accessibility preferences \r\n3) "
74 "Select \"Accessibility Apps\"\r\n4) Add this application to the approval list")};
75 juce::NativeMessageBox::showMessageBox(juce::AlertWindow::WarningIcon, title, message);
76 break;
77 }
78 case procNotFound:
79 rsj::Log(fmt::format(FMT_STRING(
"Application not found. Automation permission unknown for "
80 "{}."),
81 bundleIdentifierCString),
82 std::source_location::current());
83 break;
84 default:
85 rsj::Log(fmt::format(FMT_STRING(
"Unexpected return value when checking automation "
86 "permission for {}."),
87 bundleIdentifierCString),
88 std::source_location::current());
89 break;
90 }
91 }
92 else {
93 rsj::Log(fmt::format(FMT_STRING(
"AECreateDesc returned error {}."), aeresult),
94 std::source_location::current());
95 }
96}
void Log(const juce::String &info, const std::source_location &location=std::source_location::current()) noexcept
Definition Misc.cpp:113