Q: I'm trying to gather all available PPDs on the users system but calling PMCopyAvailablePPDs with kAllPPDDomains returns an error. How can I get a list of all PPDs on the user's system?A: PMCopyAvailablePPDs on Mac OS X 10.4 and earlier may incorrectly return no results given the kAllPPDDomains domain if any of the searched paths does not exist. Typically the missing directory is ~/Library/Printers/ as this folder was not created for user accounts created on older versions of Mac OS X. A simple work around is to call PMCopyAvailablePPDs with specific domains instead of using the kAllPPDDomains constant. Listing 1 demonstrates this method. Listing 1: A simple replacement for PMCopyAvailablePPDs
// Appends the discovered PPDs to the given mutable array, or does nothing on error.
void AppendPPDs(PMPPDDomain domain, CFMutableArrayRef destination)
{
CFArrayRef temp = NULL;
OSStatus err = PMCopyAvailablePPDs(domain, &temp);
if((err == noErr) && (temp != NULL))
{
CFArrayAppendArray(destination, temp, CFRangeMake(0, CFArrayGetCount(temp)));
CFRelease(temp);
}
}
// Calls AppendPPDs using all PPD domains to gather all available PPDs
CFArrayRef MyPMCopyAllAvailablePPDs()
{
CFMutableArrayRef ppds = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
AppendPPDs(kSystemPPDDomain, ppds);
AppendPPDs(kLocalPPDDomain, ppds);
AppendPPDs(kNetworkPPDDomain, ppds);
AppendPPDs(kUserPPDDomain, ppds);
AppendPPDs(kCUPSPPDDomain, ppds);
return ppds;
}
Document Revision History| Date | Notes |
|---|
| 2007-07-18 | First Version |
Posted: 2007-07-18
|