// clang -framework Cocoa PageRangesPrintDialog.m -o PageRangesPrintDialog 
// For firstPage:2 lastPage:3 selection, ideallly printer dialog 
// should select "Range from 2 to 3"
// but in 15.x it selects All Pages

#include <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
}
@end

@implementation AppDelegate

- (void)applicationWillFinishLaunching: (NSNotification *)notification {

    NSPrintInfo* fPrintInfo = [[NSPrintInfo sharedPrintInfo] copy];
    [fPrintInfo setUpPrintOperationDefaultValues];

    NSMutableDictionary* printingDictionary = [fPrintInfo dictionary];
    [printingDictionary setObject:[NSNumber numberWithInteger:2] forKey:NSPrintFirstPage];
    [printingDictionary setObject:[NSNumber numberWithInteger:3] forKey:NSPrintLastPage];
    [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages];

    NSPrintPanel* printPanel = [NSPrintPanel printPanel];
    BOOL fResult = ([printPanel runModalWithPrintInfo:fPrintInfo] == NSOKButton);
}

@end

int main() {
    NSApplication *application = [NSApplication sharedApplication];
    AppDelegate *appDelegate = [[AppDelegate alloc] init];
    [application setActivationPolicy:NSApplicationActivationPolicyRegular];
    [application activateIgnoringOtherApps:YES];
    [application setDelegate:appDelegate];
    [application run];
    
    return 0;
}
