Post

Replies

Boosts

Views

Activity

How to get PID from AudioObjectID on macOS pre Sonoma
3 I am working on an application to get when input audio device is being used. Basically I want to know the application using the microphone (built-in or external) This app runs on macOS. For Mac versions starting from Sonoma I can use this code: int getAudioProcessPID(AudioObjectID process) { pid_t pid; if (@available(macOS 14.0, *)) { constexpr AudioObjectPropertyAddress prop { kAudioProcessPropertyPID, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMain }; UInt32 dataSize = sizeof(pid); OSStatus error = AudioObjectGetPropertyData(process, &prop, 0, nullptr, &dataSize, &pid); if (error != noErr) { return -1; } } else { // Pre sonoma code goes here } return pid; } which works. However, kAudioProcessPropertyPID was added in macOS SDK 14.0. Does anyone know how to achieve the same functionality on previous versions?
1
0
205
4d
base::SequencedTaskRunnerHandle::Get crash on macOS while calling NSAccessibilityGetObjectValueForAttribute
Hello all, I have an application which retrieves URL from browser using accessibility. From time to time I am having this crash and I don't know the reason for it. Could you please help me? This is the stacktrace: It is happening on MacOS 13.5 and it happens on an application built for x86_64 and arm64
2
0
644
Sep ’23
Error adding app to login items using SMAppService
Hello all, I am trying to use the new SMAppService added in MacOS Ventura to add my app to login items. This is the code I am using: if (@available(macOS 13.0, *)) { SMAppService* service = [SMAppService mainAppService]; NSError* error = nil; BOOL output = false; if (setEnabled) output = [service registerAndReturnError:&error]; else output = [service unregisterAndReturnError:&error]; } However when I run the app I see this error: Domain=SMAppServiceErrorDomain Code=1 "Operation not permitted" UserInfo={NSLocalizedFailureReason=Operation not permitted} 2022-12-25 11:14:16.628 TimeDoctor2[16823:159849] Error adding or removing item Error Domain=SMAppServiceErrorDomain Code=1 "Operation not permitted" UserInfo={NSLocalizedFailureReason=Operation not permitted} I have tried to check the error detail using this command on another terminal tab: sudo log stream --debug --info --predicate "process in { '<my process>', 'smd', 'backgroundtaskmanagementd'} and sender in {'ServiceManagement', 'BackgroundTaskManagement', 'smd', 'backgroundtaskmanagementd'}" I don´t really understand the output: Filtering the log data using "process IN {"<my process>", "smd", "backgroundtaskmanagementd"} AND sender IN {"ServiceManagement", "BackgroundTaskManagement", "smd", "backgroundtaskmanagementd"}" Timestamp            Thread   Type    Activity       PID  TTL   2022-12-25 11:01:57.444537+0100 0x25272  Activity  0x514e0       306  0  smd: (BackgroundTaskManagement) BTMManager.getEffectiveDisposition 2022-12-25 11:01:57.445383+0100 0x25271  Default   0x514e0       491  0  backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: appURL=<private>, type=app, url=(null), config=(null) 2022-12-25 11:01:57.452448+0100 0x25272  Error    0x514e0       306  0  smd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] getEffectiveDisposition: error: Error Domain=BTMErrorDomain Code=-98 "(null)" 2022-12-25 11:01:57.452479+0100 0x25272  Error    0x0         306  0  smd: [com.apple.xpc.smd:SMAppService] Unable to get disposition of item: <private> error: Error Domain=NSPOSIXErrorDomain Code=3 2022-12-25 11:01:57.452378+0100 0x25271  Error    0x514e0       491  0  backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: failed to construct identifier with parameters: appURL=/Applications/Time Doctor 2.app, url=(null), type=app, config=(null) 2022-12-25 11:01:57.452495+0100 0x25272  Default   0x0         306  0  smd: [com.apple.xpc.smd:all] Found status: 3 for <private> 2022-12-25 11:01:57.842135+0100 0x25534  Activity  0x514e1       306  0  smd: (BackgroundTaskManagement) BTMManager.getEffectiveDisposition 2022-12-25 11:01:57.842254+0100 0x25271  Default   0x514e1       491  0  backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: appURL=<private>, type=app, url=(null), config=(null) 2022-12-25 11:01:57.849707+0100 0x25271  Error    0x514e1       491  0  backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: failed to construct identifier with parameters: appURL=/Applications/Time Doctor 2.app, url=(null), type=app, config=(null) 2022-12-25 11:01:57.849804+0100 0x25534  Error    0x514e1       306  0  smd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] getEffectiveDisposition: error: Error Domain=BTMErrorDomain Code=-98 "(null)" 2022-12-25 11:01:57.849828+0100 0x25534  Error    0x0         306  0  smd: [com.apple.xpc.smd:SMAppService] Unable to get disposition of item: <private> error: Error Domain=NSPOSIXErrorDomain Code=3 2022-12-25 11:01:57.849839+0100 0x25534  Default   0x0         306  0  smd: [com.apple.xpc.smd:all] Found status: 3 for <private> 2022-12-25 11:01:58.020633+0100 0x25534  Activity  0x514e2       306  0  smd: (BackgroundTaskManagement) BTMManager.getEffectiveDisposition 2022-12-25 11:01:58.020762+0100 0x25271  Default   0x514e2       491  0  backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: appURL=<private>, type=app, url=(null), config=(null) 2022-12-25 11:01:58.025436+0100 0x25534  Error    0x514e2       306  0  smd: (BackgroundTaskManagement) [com.apple.backgroundtaskmanagement:main] getEffectiveDisposition: error: Error Domain=BTMErrorDomain Code=-98 "(null)" 2022-12-25 11:01:58.025334+0100 0x25271  Error    0x514e2       491  0  backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: failed to construct identifier with parameters: appURL=/Applications/Time Doctor 2.app, url=(null), type=app, config=(null) 2022-12-25 11:01:58.304370+0100 0x25271  Error    0x514e4       491  0  backgroundtaskmanagementd: [com.apple.backgroundtaskmanagement:main] effectiveItemDisposition: failed to construct identifier with parameters: appURL=/Applications/Time Doctor 2.app, url=(null), type=app, config=(null) Could someone help me please?
1
0
1.2k
Dec ’22
Explore accessibility structure using NSAccessibility
Hello all, I have an application which explores accessibility structure. It is something similar to what Accessibility Inspector does. I have developed it using the old API. Using functions like AXUIElementCreateApplication or AXUIElementCopyAttributeValue and having to deal with pointers manually. Would it be possible to rewrite that code using NSAccessibility? I have read some doc about it but it seems it is designed to set accessibility in your OWN application, not for retrieving accessibility from external application.
1
0
971
Jul ’21
Macos Application hangs when using NSDistributedNotificationCenter and CFRunLoopAddSource
Hello all:I have MacOS application built using Qt. There I have created NSDistributedNotificationCenter to be notified when accessibility settings change (observing "com.apple.accessibility.api" ). Also I have CFRunLoopAddSource to monitor key pressed events.However when I run the program and I change accessibility application hangs and I cannot run it normally.Could someone help to see why that is happening?This is the code:Here I am creating observer: Creation/deletion is controlled by button click- (void)createObserver { [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(didToggleAccessStatus:) name:@"com.apple.accessibility.api" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately]; }And this is how I add key event logger:// Create an event tap to retrieve keypresses. CGEventMask eventMask = (CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventFlagsChanged) | CGEventMaskBit(kCGEventLeftMouseDown) | CGEventMaskBit(kCGEventRightMouseDown) | CGEventMaskBit(kCGEventMouseMoved) | CGEventMaskBit(kCGEventScrollWheel)); //| CGEventMaskBit(kCGEventLeftMouseDragged) //| CGEventMaskBit(kCGEventRightMouseDragged) //| CGEventMaskBit(kCGEventOtherMouseDragged);); CFMachPortRef m_eventTap = nullptr; CFRunLoopSourceRef m_runLoopSource = nullptr; m_eventTap = CGEventTapCreate( kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, eventMask, myCGEventCallback, nullptr); if (m_eventTap != Q_NULLPTR) { NSLog(@"CGEventTap created"); // Create a run loop source and add enable the event tap. m_runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, m_eventTap, 0); CFRunLoopAddSource(CFRunLoopGetCurrent()/*CFRunLoopGetMain()*/, m_runLoopSource, kCFRunLoopCommonModes); CGEventTapEnable(m_eventTap, true); //CFRunLoopRun(); } else { m_runLoopSource = Q_NULLPTR; NSLog(@"Error creating CGEventTap"); }Any ideas about what is going on there? And how can I solve thatThanks in advance and regards
Topic: UI Frameworks SubTopic: AppKit Tags:
6
0
1.7k
Dec ’20