Difference between revisions of "Setting a Default Printer"

From AFP548 Wiki
Jump to navigation Jump to search
Line 42: Line 42:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
You should how be able to change the default printer at will.
+
You should how be able to change the default printer at will using this python script.
  
 
Thanks to frogor and tvsutton on ##osx-server on irc.freenode.net
 
Thanks to frogor and tvsutton on ##osx-server on irc.freenode.net
  
 
[[Category:Scripts]][[Category:Settings]]
 
[[Category:Scripts]][[Category:Settings]]

Revision as of 19:39, 7 June 2012

To set a default printer so that it shows as "Default" in the "Print & Scan" Preference pane, it can be done in the following fashion:

  • Make it so that the default printer is not the last one used. We will put this into /Library/Preferences so it effects all users (Note: If this is set in the User's org.cups.PrintingPrefs.plist, the User's setting will take precedence)
defaults write /Library/Preferences/org.cups.PrintingPrefs UseLastPrinter False
  • Run this script to set the default printer. Replace 'my_queue_name' with the name of the print queue you wish to make default
#!/usr/bin/python

import objc

# Seems I need to import _some_ Framework in PyObjC, but doesn't matter what it is
import Foundation

objc.parseBridgeSupport("""<?xml version='1.0'?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='1.0'>
<depends_on path='/System/Library/Frameworks/CoreServices.framework'/>
<depends_on path='/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework'/>
<depends_on path='/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework'/>
<depends_on path='/System/Library/Frameworks/CoreFoundation.framework'/>
<depends_on path='/System/Library/Frameworks/Security.framework'/>
<depends_on path='/System/Library/Frameworks/SystemConfiguration.framework'/>
<depends_on path='/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework'/>
<depends_on path='/System/Library/Frameworks/Foundation.framework'/>
<function name='PMPrinterCreateFromPrinterID'>
<arg type='^{__CFString=}'/>
<retval type='^{OpaquePMPrinter=}'/>
</function>
<function name='PMPrinterSetDefault'>
<arg type='^{OpaquePMPrinter=}'/>
<retval type='l' type64='i'/>
</function>
</signatures>
""", globals(), '/System/Library/Frameworks/ApplicationServices.framework/Frameworks/PrintCore.framework')

thePrinter = PMPrinterCreateFromPrinterID('my_queue_name')
result = PMPrinterSetDefault(thePrinter)
print result

You should how be able to change the default printer at will using this python script.

Thanks to frogor and tvsutton on ##osx-server on irc.freenode.net