Printing to a Windows Print server
Printing to a Windows Print server
- Subject: Printing to a Windows Print server
- From: Paul Thompson <email@hidden>
- Date: Tue, 25 Jul 2006 20:33:04 -0400
Hi Everyone,
I have been working on a script that modifies the printers.conf
file to allow users to print to a Windows 2003 without having to be
bound to the directory. This script is working with a lot of help
from people on this list, and I would like to publicly thank them for
all their help. They are Mark Butler, Mark J. Reed, Emmanuel, Bill
White and David Thompson. Thanks for everything. I really
appreciate it. Having said that, I would like to return the script
to the list to hopefully help others in the future, so here it is:
--start of file
-- written by Mark Butler, Mark J. Reed, Emmanual, David Thompson and
Paul Thompson
-- reads original printers.conf to theText variable
set theText to do shell script ("cat /etc/cups/printers.conf") with
administrator privileges
-- set printersconf variable to path to tempfile as string
set printersconf to "/tmp/printers.conf"
set printersconf to (POSIX file printersconf) as string
-- set username and userpass to variables
set username to text returned of (display dialog "Enter your User
Name:" default answer "your username")
set userpass to text returned of (display dialog "Enter your Windows
password:" default answer "your password" with hidden answer)
-- replace text in variable theText to username and pass
set tempdelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "username"
set temptext to every text item of theText as list
set AppleScript's text item delimiters to username
set temptext to every item of temptext as string
set AppleScript's text item delimiters to "userpass"
set temptext to every text item of temptext as list
set AppleScript's text item delimiters to userpass
set theText to every item of temptext as string
-- safely convert to unicode special chars
set theText to the theText as Unicode text
-- this is a handler it calls the writefile below with theText
variable and printersconf variable
writeFile(theText, printersconf)
-- this creates a backup of the /etc/cups/printer.conf file
do shell script ("cp /etc/cups/printers.conf /etc/cups/
printers.conf.pre-userpass") with administrator privileges
-- this copies the tmp file back to the /etc/cups folder
do shell script ("cp /tmp/printers.conf /etc/cups/printers.conf")
with administrator privileges
-- set permissions back on the file
do shell script ("chown root:lp /etc/cups/printers.conf") with
administrator privileges
-- restart cups .... not sure you need this but it couldnt hurt
do shell script ("killall -HUP cupsd") with administrator privileges
--- this handler writes the file called earlier these are an easy way
to reuse code it can be called multiple times but only needs to be
written once...
on writeFile(thecontents, thefile)
set f to (open for access (thefile) with write permission) -- edited
write thecontents to f as string
close access f
end writeFile
--end of file
I saved it as a run only application, and placed it in a folder I
created on the local machine in /Library/. I called the folder
"Management" but you can call it what you wish. I also created a
shell script to reset the printers.conf file on logout, and placed it
in the "Management" folder as well. Here is the script:
#start of script
#!/bin/bash
# Simple script to move the printers.conf file back to original status
rm /etc/cups/printers.conf
cp -Rp /etc/cups/printers.conf.pre-userpass /etc/cups/printers.conf
exit
#end of script
The permissions and ownership are set as follows:
chmod 755 /Library/Management **permissions on the management folder**
do a chmod 777 on the files within the management folder
chown -R root:admin /Library/Management
The final part to this puzzle is the creation of Login and Logout
hooks in the local machine.
Login Hook ** This is for the AppleScript**
sudo defaults write com.apple.loginwindow LoginHook /Library/
Management/Printing.app
Logout Hook **This is for the shell script**
sudo defaults write com.apple.loginwindow LogoutHook /Library/
Management/Restorecups
The only other thing that needs to be completed is to cd /etc/
cups/ and edit the printers.conf file. Once you set the printers up
right once using the Printer Setup Utility, you cd to /etc/cups/ and
do a sudo vi printers.conf Replace the username and password that
you inputted during the setup and replace it with "username" and
"userpass" I have included a sample below for reference:
# Printer configuration file for CUPS v1.1.23
# Written by cupsd on Wed Oct 26 16:33:57 2005
<DefaultPrinter Printername>
Info Printername
Location Domain
DeviceURI smb://username:pass@Domain/ServerName/Printername
State Idle
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</Printer>
After checking to make sure it works on one machine, if you have
ARD on that machine, you can use it to push all of the information to
any other machines that you need to set it up on. You need to push
the "Management" folder located in /Library, and the printers.conf
file, the PPD folder, and printers.conf.pre-userpass files located
in /private/etc/cups/
You can also use the Send Unix command to set the login and logout
hooks on all the other machines
This was tested using a Windows 2003 server as the print server,
and a client machine running 10.4.7 using a PPC chip and it works.
Please feel free to modify it as you wish.
I hope it helps someone else,
Thank you,
Paul
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden