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.
Note: This issue has been resolved as of Mac OS X 10.5. While the work around described below still works, it is not required when running on Mac OS X 10.5 or later.
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 |
2008-08-08 |
Note that this issue has been resolved for Mac OS X 10.5 |
2007-07-18 |
Describes a work around for an issue in PMCopyAvailablePPDs on Mac OS X 10.4 and below |
Posted: 2008-08-08
|