X11 print daemon


Please note that this blog has been moved.

Now it has its own domain: mynixworld.info🙂

If you want to read the latest version of this article (recommended) please click here and I open the page for you.

I am not using my printer everyday, so why should I keep the CUPS 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:

printer

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.

About Eugen Mihailescu

Always looking to learn more about *nix world, about the fundamental concepts of arithmetic, algebra and geometry. I am also passionate about programming, database and systems administration.
This entry was posted in linux, X11 and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s