My *nix world

X11 print daemon

I am not using my printer everyday, so why should I keep the CUPS print daemon started all the time? I think a better way is to start it only when you need it (preferable before you have to print, otherwise your printer will not show up or you could not communicate with it).

The memory footprint is not so high, but anyway, why should I consume 3MB of physical RAM or 40MB of virtual RAM if I don't have to? You know, little bit from here, little bit from there, shortly you will find that many applets/plugins/daemons you might have started by default (eg: at session start-up) will eat few hundreds MB of RAM.

My solution is quite simple:

  • write a simple bash script (eg: printer) that will switch the CUPS daemon status (from started -> stopped and vice versa)
  • define a desktop keyboard shortcut (eg: Ctrl+Alt+P) that will launch that bash script
  • push Ctrl+Alt+P to start CUPS daemon or again, when you want to stop/unload it

The bash script:

#!/bin/bash

CUPS=/etc/init.d/cupsd
STATUS=$(${CUPS} status|awk '/status:/ {print $NF}')

PROMPT="To start/stop CUPS daemon you must provide sudo password"

if [ "$STATUS" != "started" ];then
        gksu -m "$PROMPT" ${CUPS} start
        MSG="started"
        ICON="devices/printer.png"
        DEFAULT_PRN=$(lpstat -d|awk '{print $NF}')
else
        DEFAULT_PRN=$(lpstat -d|awk '{print $NF}')
        gksu -m "$PROMPT" ${CUPS} stop
        MSG="stopped"
        ICON="status/printer-error.png"
fi

/usr/bin/notify-send -i "/usr/share/icons/Tango/48x48/$ICON" "Printer $DEFAULT_PRN" "CUPS has been $MSG"

Note: Don't forget to set the script as executable (chmod +x printer)

Because we involve also little bit the libnotify library we will get also a wonderful balloon that will display the status:

print daemon

Important: the icon shown above comes from my Xfce icon theme (Tango) so you might have to change the icon path in the script to fit your system configuration.

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

 
The following two tabs change content below.
X11 print daemon

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
Tagged on: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: