Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Reset CUPS printers at login System
Problem:
Printers in computer labs are disappearing. It is a mix of students deleting them and Print Center losing them.

Solution:
An AppleScript that runs at login. The AppleScript removes printers that are in the Print Center. Then it copies your backup ppd folder into the Print Center ppd folder. It then deletes the printer.conf file and replaces it with the labprinters.conf file.

Setup Information:
  1. Set up your default printers in Print Center
  2. Make a copy of your /etc/cups/ppd folder and call it labppd
  3. Make a copy of your printers.conf file and call it labprinters.conf
  4. Open Script Editor and Enter the following text:
    
    tell application "Terminal"
      do shell script "rm -r /etc/cups/ppd" password ¬
       "root password" with administrator privileges
      do shell script "cp -r /etc/cups/labppds /etc/cups/ppd" password ¬
       "root password" with administrator privileges
      do shell script "rm /etc/cups/printers.conf" password ¬
       "root password" with administrator privileges
      do shell script ¬
       "cp /etc/cups/labprinters.conf /etc/cups/printers.conf" password ¬
       "root password" with administrator privileges
      do shell script "killall -9 cupsd" password ¬
       "root password" with administrator privileges
      do shell script "cupsd" password ¬
       "root password" with administrator privileges
      quit
    end tell
    
    Replace "root password" with your root password. Make sure you save your file as an Application.
  5. Go into System Preferences -> Login Items and select your application so it will launch at login.
When you login, the application and Terminal will launch, run the commands, then quit.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,412 views]  

Reset CUPS printers at login | 7 comments | Create New Account
Click here to return to the 'Reset CUPS printers at login' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Reset CUPS printers at login
Authored by: ferris on Oct 28, '03 12:24:33PM

killall -9 cupsd is probably not the best way to terminate that process...

When you terminate a process, you generally want to try to kill it in another way first. The reason you want to use a different way to kill it first is because you want to give the service a chance to close logs, clear caches, return allocated memory, etc. If you can't kill it that way, you should kill it with a KILL signal as a last resort.

From the kill manual...

Some of the more commonly used signals:
1 HUP (hang up)
2 INT (interrupt)
3 QUIT (quit)
6 ABRT (abort)
9 KILL (non-catchable, non-ignorable kill)
14 ALRM (alarm clock)
15 TERM (software termination signal)

I suggest first using a HUP signal, and then possibly a TERM before attempting a KILL. Check the status of the process after trying to end it and then resort to more drastic measures.

If anyone thinks I'm completely wrong here, let me know otherwise I will go on thinking this... =)

---
-C



[ Reply to This | # ]
Reset CUPS printers at login
Authored by: ReznorB5 on Oct 29, '03 05:17:22AM
I wonder if it is possible to have cupsd reload its config files like you can with the shell. In the shell (csh, bash) you can do something like this to have it reload the config file:

source .cshrc


[ Reply to This | # ]
Reset CUPS printers at login
Authored by: RickoKid on Oct 28, '03 05:58:33PM

I may be missing something here - but since this applescript is all "do shell script" commands - why not just write a shell script to do it? You can make a shell script double-clickable by giving it the ".command" extension ....

Just a thought!

---


RickoKid



[ Reply to This | # ]
Reset CUPS printers at login
Authored by: ReznorB5 on Oct 29, '03 05:07:21AM
While you're at it, just make it a loginwindow script. That way it is run as root already by the loginwindow program without requiring a password (you never should save a password into a script file) and you also never have to see a terminal window or AppleScript applet launching.

http://www.bombich.com/software/lwm.html

Basically, start the first line of a text file with

#!/bin/sh
and put all of those command line things in there after it. Save it in good spot and remember to be sure it has execute permissions by root. See the LoginWindow Manager page for more info.

[ Reply to This | # ]
Never include your root password
Authored by: ReznorB5 on Oct 29, '03 05:14:02AM

NEVER, ever, ever, ever, EVER include your root password (or any password for that matter) in a script file. Even if you save it as an AppleScript application, someone can simply open it with Script Editor and view the whole contents of the script, password and all. There is one caveat in that it is possible to save a script application as Run-only, meaning that it will not allow Script Editor to open and view the application's code. However, I wouldn't trust that with my root password; would you?

At any rate, use the loginwindow scripting facility included in the OS as described at www.bombich.com and you don't need to have a password in there. The loginwindow program executes login/logout scripts as root anyway.



[ Reply to This | # ]
Reset CUPS printers at login
Authored by: ReznorB5 on Nov 19, '03 03:46:50AM
According to the cupsd man page, it looks like you can have cupsd read in a config file.
cupsd -c /etc/cups/cupsd-lab.conf
NAME
       cupsd - common unix printing system daemon

SYNOPSIS
       cupsd [ -c config-file ] [ -f ]

DESCRIPTION
       cupsd  is  the scheduler for the Common UNIX Printing Sys-
       tem. It implements a printing system based upon the Inter-
       net  Printing  Protocol,  version  1.1.  If no options are
       specified on the command-line then the default  configura-
       tion file (usually /etc/cups/cupsd.conf) will be used.

       The  -f  option forces cupsd to run in the foreground; the
       default is to run in the background as a "daemon".




[ Reply to This | # ]
Reset CUPS printers at login
Authored by: ReznorB5 on Nov 19, '03 04:14:20AM
More CUPS documentation can be found on your local disk at http://localhost:631/documentation.html.

[ Reply to This | # ]