dustinrue/ControlPlane — Issue #56: DefaultPrinterAction always succeeds
Author: dustinrue
Created: 2011-10-09 21:14:25+00:00
State: open
Labels: Actions, Bug

Code snippet might help

- (BOOL) execute: (NSString **) errorString {
PrinterSetupUtilityApplication *PSUA = [SBApplication
applicationWithBundleIdentifier: @"com.apple.print.PrintCenter"];
SBElementArray *availablePrinters = [PSUA printers];
NSLog(@"%@",[self description]);

// documentation says objectWithName returns nil if the object isn't
found
// I'm not seeing that at all so this will always succeed.
PrinterSetupUtilityPrinter *printer = [availablePrinters
objectWithName: printerQueue];

if (printer) {
PSUA.currentPrinter = printer;

if ([PSUA.currentPrinter isNotEqualTo: printer])
*errorString = NSLocalizedString(@"Couldn't set default printer!",
@"DefaultPrinterAction");
} else {
*errorString = NSLocalizedString(@"Couldn't set default printer!",
@"DefaultPrinterAction");
return NO;
}

return YES;