Struggling with a script
Struggling with a script
- Subject: Struggling with a script
- From: Paul Thompson <email@hidden>
- Date: Wed, 19 Apr 2006 10:19:28 -0400
Greetings everyone,
I have been trying to get a script running, and after struggling
with it, I'm going to need to ask for help. This script is designed
to essentially replace the username and password in the /etc/cups/
printers.conf for authenticated windows printers. So after I set up
the printers the first time, I am trying to get the script to replace
the username and password, there by allowing the next user to be able
to use the printer, after they authenticate. I am including the
script below:
-- 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
password:" default answer "your password")
-- 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
close access f
end writeFile
What happens is that after I run the script, is that the
printers.conf file ends up looking really strange, and I'm not sure
what it is. I have included a screen shot at this link: http://
homepage.mac.com/p_thompson/FileSharing5.html
If I launch the printer setup utility, after I run the script, it
tells me that there are no printers selected. It seems to wipe all
the printers out.
This is a part of how my printers.conf file originally looked,
before the script is run:
# Printer configuration file for CUPS v1.1.23
# Written by cupsd on Wed Oct 26 16:33:57 2005
<DefaultPrinter ArtandDes1>
Info ArtandDes1
Location Ucc
DeviceURI smb://username:userpass@Ucc/Server-Print/ArtandDes1
State Idle
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
</Printer>
Does anyone have any idea how I might be able to get this
working? I am currently running OS X 10.4.6. Thank you to Mark
Butler, and Mark J. Reed for all their help with this script.
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