Post

Replies

Boosts

Views

Activity

Instruments fails to record Points of Interest
I'm trying to use signposts to help profile C++ code with Instruments (with Xcode 14 beta 5), and it's not working. A section of code in question, which is definitely getting reached, starts like this static os_log_t sSignpost_log = nullptr; if (__builtin_available( macOS 10.14, * )) { if (sSignpost_log == nullptr) { sSignpost_log = os_log_create( "com.frameforge.gscn", "PointsOfInterest" ); } os_signpost_interval_begin( sSignpost_log, 99, "com.frameforge.gscn" ); } and ends like this if (__builtin_available( macOS 10.14, * )) { os_signpost_interval_end( sSignpost_log, 99, "com.frameforge.gscn" ); } In Instruments, I have a Points of Interest instrument, and in the recording options for that instrument, I added 99 and com.frameforge.gscn as a row under "signpost code names". But after recording a run, the Points of Interest instrument always shows "No Data". I tried adding an os_signpost instrument, and it shows some data, but none of mine. What am I missing?
1
0
1.2k
Aug ’22
What is default encoding for %s?
The docs on -[NSString stringWithFormat:] link to old docs on string format specifiers which say that “the %s specifier causes the characters to be interpreted in the system default encoding”. What the heck is the system default encoding? I tried googling it, and all I found was people saying that while a program may have a default encoding, the Mac OS does not.
2
0
1.1k
Oct ’22
Any way to make block from CFRunLoopPerformBlock run?
I have some NSViews that come and go during printing, and I want them to dealloc soon rather than waiting until the whole printing process is finished. The problem is that inside -[NSView addSubview:], the subview gets retained several times, and one of those schedules a release using CFRunLoopPerformBlock. But I don't have a run loop running, so that's not happening. The documentation of CFRunLoopPerformBlock says If you want the work performed right away, you must explicitly wake up that thread using the CFRunLoopWakeUp function. But calling CFRunLoopWakeUp( CFRunLoopGetMain() ) does not help, probably because the run loop is not running. If I call -[NSApplication nextEventMatchingMask: ...] in one of the standard modes, then the block from CFRunLoopPerformBlock runs, but too much other stuff also runs, such as queued notifications.
1
0
968
Oct ’22
Can a system preference pane register a login item in Ventura?
I have a system preference pane that contains a background-only app that it wants to set as a login item. I understand that the proper way to set up login items in Ventura is by using the new SMAppService framework. In order to do so, I need an instance of SMAppService. I can't create it using +[SMAppService loginItemServiceWithIdentifier:], because that assumes that the login item is embedded in the calling app, and in this case the calling app is System Preferences. That leaves having the app itself get the mainAppService class property. But when I do that, and then ask the service for its status, the result is SMAppServiceStatusNotFound. That's documented as: An error occurred and the framework couldn’t find this service. What kind of error??? When I try this, I see some messages in Console from the tccd process that look like they might be related, but they don't clarify what's wrong. Must I just give up on using a system preference pane, and make my utility a plain old app containing a helper app?
1
0
838
Oct ’22
Registering login item with new SMAppService API
I'm trying to use -[SMAppService loginItemServiceWithIdentifier:] API, and after creating the SMAppServiceInstance, its status is SMAppServiceStatusNotFound. That means it didn't find the helper app? The documentation is a little mixed up. It says that the parameter is "The bundle identifier of the helper application", but also says "The property list name must correspond to a property list in the calling app’s Contents/Library/LoginItems directory". So which is it, a property list name or a bundle identifier? And it the thing in the LoginItems directory a helper application or a property list? What I have is an app bundle inside the Contents/Library/LoginItems of the app that's calling the SMAppService API. Or in other words, the given bundle identifier parameter is the CFBundleIdentifier value in Caller.app/Contents/Library/LoginItems/Helper.app/Contents/Info.plist. Is that not the right way to do it?
3
0
2.1k
Nov ’22
How is CGRequestPostEventAccess supposed to work?
I can't find any documentation on CGRequestPostEventAccess or its friend CGRequestListenEventAccess, except for the API declarations in CGEvent.h. The fact that it returns a boolean and doesn't have a completion callback or anything like that suggests that it should be synchronous, i.e., not return until the user has decided to grant or deny permission. Experimentally, that doesn't seem to be the case, but then what does the return value mean?
3
0
1.2k
Dec ’22
Why would event tap creation fail?
On my Mac (running Ventura), so long as my app is granted accessibility permission in System Settings > Privacy & Security > Accessibility, I am able to create a global event tap like so: CFMachPortRef thePort = CGEventTapCreate( kCGAnnotatedSessionEventTap, kCGTailAppendEventTap, kCGEventTapOptionDefault, // active filter CGEventMaskBit(kCGEventKeyDown), CTapListener::MyTapCallback, NULL ); But on a user's computer, also running Ventura, the CGEventTapCreate call is apparently returning NULL, even though he's showing me a screen shot of the accessibility permission being turned on. Any ideas what I could be missing, or how to debug it?
0
0
1.1k
Jan ’23
Xcode script build phase error involving output file
I have a run script build phase that is trying to do custom code signing of a helper tool after it has been copied into the app package, so I have set both input and output files to the same thing, ${CONFIGURATION_BUILD_DIR}/$CONTENTS_FOLDER_PATH/Helpers/V40SSApp. But when I try to build, I get an error invalid task ('PhaseScriptExecution Run\ Script /mypath/Debug/installer.build/Script-BED5B762297F4C4C00C96242.sh') with mutable output but no other virtual output node I would guess that the "mutable" bit has something to do with the input and output being the same, but I don't get what it's complaining about.
1
2
910
Jan ’23
NSApplicationActivateAllWindows does not work, any alternative?
According to the documentation of the NSApplicationActivateAllWindows flag of -[NSRunningApplication activateWithOptions:], "all of the application's windows are brought forward". That does not actually happen, and has not since at least macOS 10.15. It did work in macOS 10.13, don't know about 10.14. Is there any reasonable alternative to achieve the same effect?
2
0
893
Jan ’23
CGEventTapPostEvent fails in Save panel
I have a keyboard macro utility that uses a global event tap, and requires accessibility permission. It works except when typing in the edit field of a standard Save panel. Then it just beeps when I call CGEventTapPostEvent. I'm guessing that has something to do with standard open/save panels running in some special security box ( I forget the term). If I could just turn off my utility in Save panels, that would be good enough, but I can't figure out how to detect that situation. If I look at the result of CGWindowListCopyWindowInfo, I can see the Save window, but I don't see anything special about it. Nor can I think of any way of detecting that the keyboard event I posted has been rejected.
1
0
950
Feb ’23
How to find culprit when stuck in SecureInput mode?
Sometimes, a Mac gets stuck in secure keyboard input mode, which prevents event taps from working. Googling indicates that this is a perennial intermittent problem. I've seen the suggestion to find the responsible process by using the command line ioreg -l -w 0 | grep SecureInput and looking for a PID in the output. When this happened to me today, the PID was that of the loginwindow process. That seems to be a bogus "I don't really know" result. In my case, quitting Safari cleared the problem. But is there any better way to find out the real source of the problem than quitting apps one by one?
2
0
1.3k
Mar ’23
Sandboxed helper tool crash on launch
When I try to turn on sandboxing on a helper tool, it crashes on launch. I thought my problem was solved when I found the post Sandboxed Helper Tool Crashing in libsystem_secinit, but no. I set CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO in the target that builds the tool, and verified that the only entitlement in the built tool is that com.apple.security.app-sandbox is true, but it still crashes. Backtrace: Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_secinit.dylib 0x7ff81af68400 _libsecinit_appsandbox.cold.7 + 49 1 libsystem_secinit.dylib 0x7ff81af6793c _libsecinit_appsandbox + 1831 2 libsystem_trace.dylib 0x7ff80f06649c _os_activity_initiate_impl + 51 3 libsystem_secinit.dylib 0x7ff81af671d4 _libsecinit_initializer + 67 4 libSystem.B.dylib 0x7ff81af7b8b9 libSystem_initializer + 286 5 dyld 0x7ff80efa1618 invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 172 6 dyld 0x7ff80efe0de9 invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 242 7 dyld 0x7ff80efd4ef7 invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 557 8 dyld 0x7ff80ef870b7 dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 245 9 dyld 0x7ff80efd40a7 dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 175 10 dyld 0x7ff80efe08d2 dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 470 11 dyld 0x7ff80efa14f6 dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 150 12 dyld 0x7ff80efa9fd4 dyld4::PrebuiltLoader::runInitializers(dyld4::RuntimeState&) const + 30 13 dyld 0x7ff80efc100d dyld4::APIs::runAllInitializersForMain() + 71 14 dyld 0x7ff80ef8c369 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 3743 15 dyld 0x7ff80ef8b281 start + 2289
2
0
1.2k
Mar ’23