I want to print the content of a WKWebView. I've done some searching, and many people have struggled with this over the years. Some claimed success, but their solutions don't work for me. One person created images for each pages and printed that, but then if you were to print to PDF, you'd get a PDF containing images rather than text.
If I just call the printView(_:)) method of the view, I get blank pages.
With the following more elaborate code, I get a partial printout, 11 out of what should be about 13 pages.
let info = NSPrintInfo.shared
info.topMargin = 72.0;
info.bottomMargin = 72.0;
info.leftMargin = 72.0;
info.rightMargin = 72.0;
info.isVerticallyCentered = false;
info.isHorizontallyCentered = false;
info.horizontalPagination = .fit;
info.verticalPagination = .automatic;
let printOp = webView!.printOperation( with: info )
printOp.canSpawnSeparateThread = true
printOp.view?.frame = NSMakeRect( 0, 0,
info.paperSize.width, info.paperSize.height )
printOp.runModal(for: webView.window!, delegate: self,
didRun: nil, contextInfo: nil )
When I run the above under the debugger, I see console messages saying
CGContextClipToRect: invalid context 0x0.
Once the print dialog appears, if I touch (but not change) the selected printer, then the page count changes to the correct value.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
When making a disk image for software distribution, it used to be possible to make a Finder window automatically open when the disk image is mounted, using a command like
sudo bless --folder dirPath --openfolder dirPath
on a read-write disk image.
However, as of Ventura, attempting to do so produces an error message
bless: The 'openfolder' option is deprecated
and the command fails to do what I want.
Disk images that were set up this way in years past continue to work. I suppose I could duplicate a working writable disk image, remove the old contents and put in new contents, but that seems a little hacky. Is there an alternative?
Topic:
Developer Tools & Services
SubTopic:
General
I'm getting occasional crashes, which have not happened while running under a debugger and I haven't figured out how to reproduce. I wonder if anyone can help me glean more information from a crash report. Here's the main part. This particular report if from macOS 14.2 beta, but I've also seen it from 14.1.1.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018
Exception Codes: 0x0000000000000001, 0x0000000000000018
VM Region Info: 0x18 is not in any region. Bytes before following region: 140723250839528
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
mapped file 7ffcaf60c000-7ffcd7f48000 [649.2M] r-x/r-x SM=COW ...t_id=b7394f27
Error Formulating Crash Report:
PC register does not match crashing frame (0x0 vs 0x1022A3630)
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 <translation info unavailable> 0x1022a3630 ???
1 libsystem_platform.dylib 0x7ff819d0b393 _sigtramp + 51
2 AppKit 0x7ff81d3549a6 -[NSControl _setWindow:] + 59
3 AppKit 0x7ff81d413c19 -[NSSegmentedControl _setWindow:] + 42
4 AppKit 0x7ff81defd3be __21-[NSView _setWindow:]_block_invoke.391 + 324
5 AppKit 0x7ff81d33a62c -[NSView _setWindow:] + 1886
6 AppKit 0x7ff81defd3be __21-[NSView _setWindow:]_block_invoke.391 + 324
7 AppKit 0x7ff81d33a62c -[NSView _setWindow:] + 1886
8 AppKit 0x7ff81d572d08 -[NSWindow dealloc] + 922
9 MyApp 0x1011b6b81 -[JWWindow dealloc] (in MyApp) (JWWindow.m:37)
10 Foundation 0x7ff81b3d179c _NSKVOPerformWithDeallocatingObservable + 151
11 Foundation 0x7ff81acc6d54 NSKVODeallocate + 150
12 libobjc.A.dylib 0x7ff8199189d7 AutoreleasePoolPage::releaseUntil(objc_object**) + 169
13 libobjc.A.dylib 0x7ff819915cf0 objc_autoreleasePoolPop + 235
14 CoreFoundation 0x7ff819d794a1 _CFAutoreleasePoolPop + 22
15 Foundation 0x7ff81ac869ea -[NSAutoreleasePool drain] + 133
16 AppKit 0x7ff81d315694 -[NSApplication run] + 653
17 AppKit 0x7ff81d2e9662 NSApplicationMain + 816
18 MyApp 0x100ef5034 start (in MyApp) + 52
I can see that it involves deallocating a window as part of draining an autorelease pool, but does the presence of _NSKVOPerformWithDeallocatingObservable mean that KVO is involved somehow? And does the note "PC register does not match crashing frame" tell me anything?
When I'm running my Mac app in the Xcode debugger, and it launches a helper app, the helper crashes with a dyld error. This does not happen if I am not debugging.
Termination Reason: Namespace DYLD, Code 1 Library missing
Library not loaded: @rpath/Cal3D.framework/Versions/A/Cal3D
Referenced from: <3C1A67BA-5545-31A2-86C5-77104B0194FE> /Volumes/VOLUME/*/SBEngineLib4.framework/Versions/A/SBEngineLib4
The frameworks SBEngineLib4.framework and Cal3D.framework exist in the main app. The helper app does not contain any frameworks, but does contain dylib versions of those frameworks, which I suppose is confusing things somehow.
When I pass a file path url of a file in iCloud Drive to -[NSWorkspace openURLs:withApplicationAtURL:configuration:completionHandler:], it fails. There is no exception, and the completion handler isn't called. This is in a sandboxed app on macOS 26.1.
NSWorkspaceOpenConfiguration* config = NSWorkspaceOpenConfiguration.configuration;
config.activates = YES;
config.promptsUserIfNeeded = YES;
NSLog(@"performDrag 2 with %@", filePathObs);
[NSWorkspace.sharedWorkspace
openURLs: filePathObs
withApplicationAtURL: appURL
configuration: config
completionHandler:
^(NSRunningApplication * _Nullable app, NSError * _Nullable error)
{
NSLog(@"performDrag 3");
if (error != nil)
{
NSLog(@"%@\n%@", error, filePathObs);
}
NSLog(@"complete performDrag");
}];
NSLog(@"performDrag 4");
In the debug log, the performDrag 2 and performDrag 4 messages appear.
I also looked in the Console log, but the only messages that mention my app don't mean anything to me.
AFIsDeviceGreymatterEligible Missing entitlements for os_eligibility lookup
6c Reentrant message: kDragIPCCompleted, current message: kDragIPCLeaveApplication
Is there any way to read/write preferences for a Mac app group using the defaults command? I'm talking about the stuff you would programmatically manipulate using [NSUserDefaults initWithSuiteName:], and that is stored on disk in ~/Library/Group Containers. If I just say defaults read <suite name>, it tells me the the domain does not exist.
If I use -[NSView dataWithPDFInsideRect:] to create a PDF from an NSTextView, I get a single-page PDF with stuff past the bottom cut off. What do I need to do to get pagination to happen? Would embedding the NSTextView in an NSScrollView help?
I would like to install the beta of macOS 15 on an empty volume, rather than on top of an existing version of macOS. Is it possible? I see that I can download an .ipsw file, but I don't understand what can be done with it.
I have a Mac app with a background-only helper app that needs to have Accessibility permission in order to use an event tap that can modify events. This has worked OK through Sonoma, but in the Sequoia beta it is failing to create the tap. C code to test the ability to create the event tap:
static CGEventRef _Nullable DummyTap(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *userInfo)
{
return NULL;
}
static bool CanFilterEvents( void )
{
CFMachPortRef thePort = CGEventTapCreate(
kCGSessionEventTap,
kCGTailAppendEventTap,
kCGEventTapOptionDefault, // active filter, not passive listener
CGEventMaskBit(kCGEventKeyDown),
DummyTap,
NULL );
bool madeTap = (thePort != NULL);
if (madeTap)
{
CFMachPortInvalidate( thePort );
CFRelease( thePort );
}
return madeTap;
}
So, on Sequoia, CanFilterEvents returns false in spite of Accessibility permission being granted in System Settings. CGPreflightPostEventAccess also returns false, but AXIsProcessTrusted returns true.
I tried making a non-background-only test app, and when that has Accessibility permission, CanFilterEvents, CGPreflightPostEventAccess, and AXIsProcessTrusted all return true. Suggestions on what to try next?
In the General system settings panel in Ventura, under Login Items, there are 2 sections: "Add Login Items", and "Login Items Added by Apps". What is this second category, and where can I find more about how to create such login items?
I have an app group to share settings between a main app and a helper. This is accessed using [[NSUserDefaults alloc] initWithSuiteName: @"FDHC2KMZ6V.com.jwwalker.autopairs.suite"]. What's puzzling me is that if I go to Terminal and enter
defaults read FDHC2KMZ6V.com.jwwalker.autopairs.suite
it tells me that the domain does not exist. Is this a bug in the defaults tool, or is there some trick I'm missing?
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?
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?
If I enter a feedback ID like FB11832484, the last digit does not get highlighted, and is not part of the automatically-generated URL linked to the text. Looks like someone assumed that there will never be more than 7 digits in the feedback ID.
In macOS 13.2, the NSTrackingEnabledDuringMouseDrag flag for NSTrackingArea is broken, i.e., mouse-entered and mouse-exited events are not sent during a drag. This problem did not exist in macOS 12. I've filed a bug report, FB11973492, just wondering if anyone knows a workaround.