Author Archives: Gen2ly

Sleep Button in KDE 4 Workaround

If you noticed that pushing the sleep button does nothing in KDE 4 (as of this writing <=4.3.3), this is because of a bug in KDEs’ power management tool Powerdevil. It appears that in most cases Powerdevil does not recognize the Xorg servers’ XF86Sleep key. To fix this, you may be able to rebind the sleep key in the KDE control panel.

Add a New Input Action

Open System Settings then Input Actions. Then add a new Global Shortcut:

Name it ‘Sleep’ or whatever you like. Add a Comment if you wish and in the Trigger tab select your hotkey. Try setting the sleep key first. For me, setting the hotkey to the sleep key didn’t work because I believe that Powerdevil already has it bound. There have been others though that look to have sucessfully done so.

Note: If someone knows of a way to decouple the Powerdevil sleep key please let me know.

I bound mine to Scroll Lock (hope I don’t need it anytime soon) then in the Action tab entere the dbus command to suspend to ram:

qdbus org.kde.kded /modules/powerdevil suspend 2

If this doesn’t work, try ‘suspend 1′. If you would like to suspend to disk:

qdbus org.kde.kded /modules/powerdevil suspend 4

One More KDE 4 Gmail Checker

Not so far back, I was attempting to cope without a mail notification program on my KDE 4 destkop and not doing so well about it. There are plenty mail notification applets available on Linux most are for Gnome though and they pulled in alot of dependencies (mail-notification , gnubiff, checkgmail-notify-osd). For KDE a couple plasmoids exist (gx-mail-notify, emailnotify). I like both of these, particularly gx-mail-notify (the later though I found to be buggy). I also thought about kbiff from KDE 3 but it doesn’t look like it’s going to be updated to KDE 4. I’d been using KCheckGmail but somehow, someway, it broke recently. Yeah, I tried replacing the plasmarcs and recreating KCheckGmails’ configuration file but got nothing. Besides re-building all my KDE configurations again (~/.kde4) (which I’m not going to do [but does work when I created a new user]) I was up the creek. Luckily though I stumbled upon KGmailNotifier when I was on KDE apps. Marcel has taken KGmailNotifier just recently and updated it to KDE 4. The first thing I noticed is that KGmailNotifier doesn’t use the KDE 4 notification system and instead uses it’s own built-in popup. The effect is nice and has a nice display though I found that sometimes it will miss a mouse click. Beside that is a nice application. Both KCheckGmail and KGmailNotifier offer about the same functionality so I could go either way. For now I’m happy that I got my mail notifications back. Thanks for your work marcel.

plasmabac – When plasma solidifys.

Plasma being a new technology for KDE it can still, at times, behave like a bad child. Alot of you may have noticed that plasma from time to time will have the tendency to cause the desktop to freeze or crash. This usually happens with widgets that have bugs in them or if there are errors in the plasma configuration files. Instead of losing all my plasma configurations anytime plasma goes rogue, I’ve made it a routine to back them up regularly. I decided to build a script that can backup the current plasma configs and then automate it to run once a week. The script will both backup and restore:

plasmabac b
plasmabac r

When you choose to restore, it will give you a list of saved plasma configs by date:

plasmabac r
 0) plasmarcs-2009-10-13.tar.gz
 1) plasmarcs-2009-10-18.tar.gz
 2) plasmarcs-2009-10-23.tar.gz
 3) plasmarcs-2009-10-24.tar.gz
 4) plasmarcs-2009-10-25.tar.gz
 5) plasmarcs-2009-10-29.tar.gz
 6) plasmarcs-2009-11-01.tar.gz
 7) plasmarcs-2009-11-02.tar.gz
Choose the plasma configuration to restore: 

To backup on a weekly basis, add it to the cron jobs:

  57  00  *   *   0       ~/.bin/root/backup/plasmabac b    # w - plsm cnfgs
# |   |   |   |   |   user
# |   |   |   |   weekday (0-6) (Sunday=0)
# |   |   |   month (1-12)
# |   |   day (0-31)
# |   hour (0-23)
# minute (0-59)

The script will automaticaly delete configurations older than two months to prevent overflow.

Enjoy :)

# plasmabac - backup and restore local plasma config


# Use filename as program name

# Text color variables
txtbld=$(tput bold)       # bold
txtund=$(tput sgr 0 1)    # underline
bldblu='\e[1;34m'         # blue
bldred='\e[1;31m'         # red
bldwht='\e[1;37m'         # white
txtrst='\e[0m'            # text reset

plasmarcs=($(find "$userdir"/.kde4/share/config -type f -name "plasma*"))
bkpplasmarcs=($(find "$backdir" -type f -name "plasma*" | sort))
date=$(date +%F)

# Display usage if full argument isn't given
if [[ -z "$@" ]]; then
  echo " $prog b|r - backup or restore plasma configurations"

# Check if the directory exists and user has access to it
if [[ -n $(ls "$backdir" 2>&1 | grep denied) ]]; then
  echo -e "$warn User doesn't have access to the backup directory"
  if [[ ! -d "$backdir" ]]; then
    mkdir "$backdir"
    echo -e "${bldblu}*${txtrst} KDE 4 plasma config backup directory doesn't exist.  Created."

# Delete backups older than two months
if [[ -n "$(find "$backdir" -mtime +60)" ]]; then
  find "$backdir" -mtime +60 -exec rm {} \;
  echo -e "$pass Configurations older than two months deleted"

case $1 in
  b | backup )  tar -czpf "$backdir"/plasmarcs-"$date".tar.gz ${plasmarcs[@]}
                echo -e "$pass Plasma configurations backed up. (${bldwht}$date${txtrst})"
  r | restore ) for((i=0;i<${#bkpplasmarcs[@]};i++)) ; do
                  echo -e " ${txtbld}${i}) ${bkpplasmarcs[$i]##*/}${txtrst}"
                echo -n "Choose the plasma configuration to restore: "
                read restore
                tar -xvf "$selection" -C /
                echo -e "$pass Restored plasma configs: ${txtbld}${bkpplasmarcs[$restore]##*/}${txtrst}"

Mplayer as default DVD player in KDE 4

I got a thing for MPlayer. There’s a good number of video players in Linux but the simplicity of MPlayer has always made it what I like to use. I like to use MPlayer without the GUI because once I learned the keybindings it makes for fast and bare-bones video player (to learn a little more about setting up MPlayer settings, look at this page). To be able have MPlayer as your default video player in KDE 4 you’ll have to do change mime associations and add MPlayer to the ‘Open with’ dialog.

Changing mime Associations

If you install MPlayer with a GUI, you can skip this step because it should install an icon and .desktop file (file for displaying in the Application menu and listing associated file types). If you install MPlayer without a GUI, likely it will not have one. Here’s a ‘mplayer.desktop’ file you can use:

[Desktop Entry]
GenericName=Multimedia player
Comment=Multimedia player
Comment[es]=Reproductor multimedia
Comment[fr]=Lecteur multim├ędia
Comment[it]=Lettore multimediale
Exec=mplayer %F

Place this file in the application menu folder:

mv mplayer.desktop ~/.local/share/applications/

And the icon that goes with it:

mplayer icon

mv mplayer.svg ~/.local/share/pixmaps

Open ‘System Settings’ (or whatever your distribution calls it), click on the Advanced tab and choose File Associations. Then select video in ‘Known types’. Go through videos you’d like MPlayer to open as default and place MPlayer at the top of the list then ‘Apply’. Note, you may have to wait a minute after doing the previous action before the mime types get registered. Now videos that you have saved on you hard drive can be clicked and loaded with MPlayer.

Mplayer in ‘Open with’ Dialog

Adding to Device Actions in System Settings

It may be faster and quicker to copy and paste the configuration file I post in the next step. I put this method up is case you want to learn how to add and configure special device actions.

Open ‘System Settings’ and go to the Advanced tab and click on Device Actions. ‘Add’ a new action named ‘MPlayer’. Add a new action like: ‘mplayer dvdnav://’. Most distributions compile MPlayer with DVD navigation now so this should work. Remove ‘The device must be of the type Storage Volume’ and ‘The devices property Storage.Volume.ignored must equal false’ properties. Select ‘All of the contained conditions must match’ then click ‘Add’.

  Requirement type: Contains Other Requirements
  Requirement type: Is A Requirement

Select ‘All of the contained conditions must match’ then ‘Add':

  Requirement type: Is A Requirement
  Restriction type: Compare Value To
  Device type:      Storage Volume
  Value name:       Ignored
  Equals:           false

Add another to ‘All of the contained conditions must match’ and add this to recognize you DVD disk:

  Requirement type: Is A Requirement
  Restriction type: Compare Value To
  Device type:      Optical Disk
  Value name:       Avaliable Content
  Equals:           'Data|VideoDvd'

Save the configuration and you should see the ‘Open with’ dialog display MPlayer. For me this didn’t though and I ended up creating the configuration manually and only then did it show up after I rebooted. Rebooting should be necessary though and likely this step would have worked if I had just logged out and back in again. I had been playing with the configuration a bit before I learned how to do this and likely this is a bug in system settings. If this doesn’t work for you look at the alternative below.

Using a Pre-made Configuration

Use this pre-built configuration if you don’t want to do the above and put it in the right directory to have MPlayer appear in the ‘Open with’ dialog:

[Desktop Entry]
X-KDE-Solid-Predicate=[[ StorageVolume.ignored == false AND OpticalDisc.availableContent == 'Data|VideoDvd' ] OR [ StorageVolume.ignored == false AND OpticalDisc.availableContent == 'Data|VideoDvd' ]]

[Desktop Action open]
Name=Open with Video Player (Mplayer)
Exec=mplayer dvdnav://

Now move it to the right directory:

cp Mplayer.desktop ~/.kde4/share/apps/solid/actions/Mplayer.desktop

Again, you may have to login/logout before it becomes available (reboot worked for me but shouldn’t be necessary).

And you should be good. Enjoy MPlayer!

Command Line Calculator

I can usually type faster in the terminal than doing mouse click on a gui calculator, so I created this scipt to be able to do it quickly from the terminal. There are alot of command line calculators out there so use the one you are comfortable with but I like using bc because of the syntax. For example, you can type:

calc "6/(3*10)"

or something more complex:

calc "8^2*(10/2+(13.2032565*2030)/.349548)" 100

100 is optional, it will specify how many decimals you want to carry it out to (the default is 4).

Chromium test (two days without Firefox)

With Firefox becoming fully-fledged, I wasn’t on the look-out to try another browser. Firefox is a well-done application for all it has to do. I can’t say I’m a complete friend of Firefox as the two huge security exploits in the last year will always keep me a bit leary. IMHO, something so predominantly geared on the internet can’t have these types of ommisions. But like good friends we learn to forgive and move on, and Firefox seems to have patched our ways.

When people began doing the “OMG Chrome” thing, I held short, but not because Google has never betrayed my trust (as for as my knowledge goes). For such a influential and in-position company, this begets me a tremendous respect. As one former execuative of AIG said though, “We just got too big.” And it’s true, one bad grape taints the wine. Perhaps I’m just too paranoid, but I didn’t want to touch the thing until I knew that hax0rhig didn’t come tromping into my living room. Curiousity, however, creeped in short of my expectations and I have been taken quick glimpses of Chromium the last two months. And, in this time, Chromium has made some some good gains.

It’s a bit too early to make comparisons, Chromium may not even be considered beta yet by the developers. But lately a lot of pieces have come together to make Chromium closer to becoming an everyday browser. For example, it’s gotten proper font rendering, all the options work now, and (as far as I tested) it no longer hangs. I was interesting in seeing if Chromium could be used two days as my regular browser.

The first thing I’ll say (like everybody else) is that it is fast. Now having a 64bit Firefox with tracemonkey I can see what they mean when they say how much of an improvement faster javascript rendering makes. I did a sunspider test on the new Firefox and got 1600 score. Running the same test with Chromium got me a 1200 score. This may look like a pretty big difference but in reality I couldn’t really tell. On espn, gmail, wordpress dashboard, load times were about the same. Possibly because they are both really fast, and possibly Firefox’s Gecko rendering engine is a little faster with HTML than Webkit is. Not sure.

One of most apparent difficulties I had with Chromium was that it has no setting for minimum font size. I found alot of sites that still like to use pixel size font settings (oh, Arial 8, we love you), so that at times I’d get very large fonts while other fonts had me rocking forward to be able to read them. Not sure this will be fixed anytime soon either as (if I remember right) the news Windows version didn’t have this feature either. Though some fonts may have been small, overall they were a more clear to read. Firefox has some built-in font rendering which isn’t bad but somehow it conflicts with my fontconfig settings and the fonts look a little bit worse than they do in other applications.

Chromium also does good on screen real-estate. The address bar that can also do searchs is a great idea in keeping things simple. I found it’s history search to be not as good as Firefox’s at finding the most used addresses but possibly this is because it imported Firefox’s and didn’t have the statistics about how often they were used.

I think Google is going to have to look at layout though. Chrom(e|ium) uses a new tab to get easily to a new page if you don’t want to use the address bar (or don’t know the address). In the new tab are nice thumbnails of commonly used sites and a bookmark bar on top. But I often found myself wanting to get to a bookmark from an already opened page which required a couple extra steps. I’d also like to see the title bar come back. Currently the title only shows on the tab and a good portion of it can’t be read.

Firefox does better with it’s find search. Why Google didn’t implement the ‘/’ I haven’t figured out yet. Firefox’s extensions though may make it the most popular browser out there. I don’t use many of them myself (NoScript, theme, Dictionary) but realize they might be the main reason Firefox is getting more popular. Besides that though, I’d say these two browsers are about equivicable at least in functionality. I didn’t get to test every site I commonly visit but on a couple sites Chromium does shows that it doesn’t have quite as good of flawed HTML/CSS fixing as Firefox does. But for the most part browsing was comfortable and felt like it did in Firefox. I don’t plan on leaving Firefox (there’s really no reason to), but with as far as Chrome has come so far, it’s be interesting to see where Chrom(e|ium) is in a year or two.

Kwrite Setup

HeaderI love Kwrite. Basically when I do text things, I use vim for creation and Kwrite for editing. When it comes to moving large blocks of text and having to scroll quickly through a text file, a gui text editor is needed. Kwrite does good with syntax-highlighting and enables me to easily work on more than one text file at once. Although Kwrite is good by default, it takes a little setting up to get it to behave as expected. Here’s how I setup Kwrite.

Open up the configuration: Settings > Configure Editor


Turn on ‘Dynamic Word Wrap’. This allows words to be wrapped but doesn’t create a new line. This way you avoid having to scroll left and right to get to text.


Disable all borders. Line number isn’t really needed if you use the status bar (enabled by default), icon border I never really found a use for, and folding is nice but since Kwrite doesn’t remember this setting and going through file and collapsing everything, everytime, is more trouble than it’s worth.

Fonts and Colors

Kate’s built in color schema’s don’t have alot of options. I found someone who brought KDE 3.5 Kate’s color schema to Kwrite (I believe Kwrite is a trimmed down version of Kate). I wish I had the link, but I don’t so I’ll put it up here.

Additional Kwrite Color Schemas

You’ll need to put the files in ‘~/.kde4/share/config’ and change ownership of them. I’m not sure if the katepartscriptrc is needed but it’s not going to hurt to add it. Be sure to back up the originals first though. You can change the schema with the ‘Default schema for Kwrite’ dropbox.



For tabulators think about doing ‘Insert spaces instead of tabulators’. In some documents you’ll find people use a mix of space for tabs and tabs themselves which can make for some odd formatting depending if tab spacing is different. I also like to ‘Highlight tabulators’. For ‘Tab width’ I found that ‘2 characters’ works good for being able to scroll text easily and still have easily discerable indentations.

Static Word Wrap

Static word wrap I leave off. Static word wrap forces line breaks when you reach the end of the line. This is good if you are say writing a man page, but not so good if you are building a script.


In Misc I like to ‘Highlight trailing spaces’. Sometimes I’ll leave an empty space at the end of the line and have to edit something else. When I get back, it’s a nice reminder that I don’t have to enter a space again.

Intentation Tab

Indentation Actions

Having ‘Backspace key in leading blank space unindents’ checked is a good idea if you use spaces for tabs.

Auto Completion Tab

I’m not sure even how auto-completion in Kwrite even works. Supposedly you are able to Ctrl-Space when you see a popup and the word will be printed. It’s never worked for me though and I find the popups semi-distracting so I disable ‘Auto completion enabled’.


Automatic Cleanups on Load/Save

Though hardly necessary, it does make a nice clean document when you select ‘Remove trailing spaces’.

Advanced Tab – Backup on Save

Kwrite does the same thing as default Vim does and leaves a nice clutter of backup files all over your filesystem. Though it is nice enough to have a backup, I’m usually good enough to remember to backup important text files before I edit them. Uncheck ‘Local files’ to avoid a nice trail [A-Za-z0-9]~ files everywhere.

For the truly paranoid

HeaderI’ve been reinstalling my system as of late (been way too along a comin’) and I realized that I hadn’t set up a firewall yet. This, in turn, had me think how many ports were open. I was up too late and probably had too many cokes by then. I had given myself a dead simple root password so that I could finish the install and began getting that tightening, turning, wretching in the belly feeling. I couldn’t help thinking that, “This could be the time that some random joe comes along and finds a nice open gate”. Doesn’t make much sense now, but decided then to build a script that toggles a 20 character random password to relieved my paranoia. Here it is for anyone who can find use of it. Oh, and I did get my install done.

# randompass - toggle between random and known passwords for users

# User passwords to protect
users=(root todd akau)

# Program name from it's filename

# Text color variables
txtund=$(tput sgr 0 1)          # Underline
txtbld=$(tput bold)             # Bold
bldred=${txtbld}$(tput setaf 1) #  red
bldblu=${txtbld}$(tput setaf 4) #  blue
bldwht=${txtbld}$(tput setaf 7) #  white
txtrst=$(tput sgr0)             # Reset
info=${bldwht}*${txtrst}        #

# Check if users exist, if they don't remove from the users array
list="${users[@]/%/|}"    # Puts array to list, add pipe after each user
users=($(grep -Eo "^(${list// })\>" /etc/shadow)) # strip spaces, end of word

# Password generation
passgen=$(< /dev/urandom tr -dc A-Za-z0-9/.$ | head -c20 | xargs | cat)

# Variables for current passwords
for user in ${users[@]}; do
  eval "curpw$user=\$(grep \$user /etc/shadow | awk -F : '{print \$2}')"

# Save original passwords (first run)
for save in ${users[@]}; do
  if [ ! -f /root/pass$save ]; then
    grep $save /etc/shadow | awk -F : '{ print $2 }' > /root/pass$save
    echo "$pass Saved ${txtund}$save${txtrst} password"

case $1 in
  h ) echo " $prog <*u>- toggle random and known passwords. u - update known"
  u ) echo "$warn Be sure no random passwords are set before updating passwords!"
      echo -n "Update known passwords file(s)? "
      read update
      if [[ $update == [Yy] ]]; then
        for known in ${users[@]}; do
          grep $known /etc/shadow | awk -F : '{ print $2 }' > /root/pass$known
          echo "$pass Updated ${txtund}$known${txtrst} password"
        echo " Passwords not updated"
  * ) if [[ "$curpwroot" == "$(cat /root/passroot)" ]]; then
        for u in ${users[@]}; do
          usermod -p $passgen $u
          echo "$pass Generated password for ${txtund}$u${txtrst}."
        for u in ${users[@]}; do
          usermod -p $(cat /root/pass$u) $u
          echo "$pass Restored password for ${txtund}$u${txtrst}."

Advanced Urban Terror Setup

Update: 4.2 Release changes added

One of the greatest games I’ve ever played is Urban Terror. Urban Terror takes Quake 3 and transforms it to near perfection (in my opinion). Urban Terror is one of the the most successful open source, free-to-play, games of all time. The amount of time to play it, learn it, master it, is a great pleasure. This guide will show how to optimize and setup Urban Terror for best performance and usability.

Urban Terror is based on the Quake 3 engine that was released by id software in 2005. Since then it has been edited, refined, fixed, and added to under the name of the ioquake engine. The ioquake team has done an awesome job of keeping the engine up to date and running well as well as adding 64bit support, ogg support, in engine VOIP support… The current version of Urban Terror is 4.2 and you should be able to find it in the repositories for your distribution.

Keyboard Layout

Though the default layout of Urban Terror keybindings can be gotten by with, advanced users know that having to take the hands off the default keyboard positions too many times means trouble. In a game were milliseconds count this best be avoided. Keeping grouping of commonly used keys close to your left hand is good practice. This keyboard layout groups commonly used functions but is generic and should work well for any game type. However, since I find myself playing capture the flag most of the time, the automated chat (radio commands) are for CTF (the radio commands are easy enough to change in the configuration below):


id software really knows how to make a game engine, the capabilities and options in the engine seem nearly unlimited. I’ve gone through and discovered the most important values to set on Urban Terror.

The configuration files are stored in ~/.q3a/q3ut4/. For automatic configuration inheriting, Urban Terror will look for a file called autoexec.cfg here. Instead of going over all the settings that can be done, I’ll just provide the configuration file which has comments on all the settings.

Testing edits to the configuration can be done within the games’ console. Pressing the tilda key (`) will bring it up. First thing I do is change r_mode to 4 and turn full screen off to be able to reach the configuration in the text editor:

r_mode 4
r_fullscreen 0

Changes in the console will not make changes to autoexec.cfg. Testing settings can be typed directly in the console or make the edit to the configuration and type (to reload it):

exec autoexec.cfg

If there are errors in the configuration file they will be displayed after typing this.

Configuration file below will need a quick go-ever before using but is mostly good. Edits needed will likely be r_custom, cg_selectedPlayerName, mouse sensitivity and maybe a few others. Forgive the syntax highlighting below, github does not correctly recognize id config files, Yeesh.

HTML Entities from the Command Line

While doing HTML work I tend to do my work with text editors. For this, I use Arachnophilia a Java HTML editor with easy, editable, customizable tags (Review here).

Arachnophilia has support to convert characters to HTML entities but isn’t easy to get to (HTML > More Functions > Char to Entity. There are various web sites that do but if willing to use the terminal they can be quickly gotten there as well. Thanks to script by Darren this can be done easily. It requires script Perls’ HTML::Entities module to do so (for help installing Perl modules look at this page). You’ll probably need redirect the script to point to the Perl program proper:

whereis perl

More than likely its in /usr/bin/perl. After fixing that run the script. This will put you in a sub-shell that you can copy and paste characters to be encoded:

You can also convert a whole file. This will print to standard output (terminal text):

htmlentities filename

Or convert a file by doing:

htmlentities  < file > convertedfile

movietime – Stop Powersaving to Watch a Movie

Getting down to watching you favorite movie on your computer? Start the movie, sit down, grab your snack and ten or so minutes later the screen goes blank. This happens in Linux because the desktop has built-in defaults for display power management (DPMS) and screensaving. Timeout settings can vary from distribution to distribution but they all got them. Here’s a basic script that can toggle DPMS and screensaving on and off.

Xorg Server Settings

You can set the values of blank, standby, suspend, and off in the the xorg server configuration file. The defaults are: 15, 20, 30, and 40 minutes. Personally I like to set these to better match how I use my computer:

Section "Monitor"
  Identifier  "Monitor0"
  Option      "DPMS"    "true"  # display power management on (true/false)

Section "ServerFlags"
  Option "BlankTime"    "13"    # LED still on, no + (0 disables)
  Option "StandbyTime"  "15"    # turns off LED
  Option "SuspendTime"  "0"     # turns off LED, and most power
  Option "OffTime"      "50"    # turns off all power

BlankTime is just a cheap screensaver and only real use for me is to tell me that I forgot to disable dpms while watching a movie. Doing this saves me a few seconds that StandbyTime requires to turn on the display again. SuspendTime and StandbyTime are nearly the same thing so I don’t bother setting SuspendTime.


Here’s movietime. Movietime should work with just about any type of desktop environment (at least any system with dbus installed which really all of them do). If you aren’t familiar with having your own scripts and how to run them, take a look at this page).

# movietime - disables power savings to watch movies.

# Movietime options
#  Resume time - resume normal display pm and suspend after set time.
# 0 = disabled, time in minutes
if [ $resumetime = 0 ]; then 
  resumetime=1440 # Re-enable resume after a full day

# Check that values for 'resumetime' are numbers
if [ $(echo $resumetime | sed 's/^[-+0-9][0-9]*//' | wc -c) != 1 ]; then
  echo "$warn variable 'resumetime' is not a number.  Exiting."

# Name of suspend script

# Program name from it's filename.

# Text color variables
txtund=$(tput sgr 0 1)          # Underline
txtbld=$(tput bold)             # Bold
bldblu=${txtbld}$(tput setaf 4) #  blue
bldwht=${txtbld}$(tput setaf 7) #  white
bldred=${txtbld}$(tput setaf 1) #  red
txtrst=$(tput sgr0)             # Reset
info=${bldwht}*${txtrst}        # Feedback

# Check that Xorg server is running
if [[ -z $(ps aux | grep /usr/bin/X) ]]; then
  echo "$warn The Xorg server is not running."

# Check if user is regular user
if [ $(whoami) == "root" ]; then
  echo "$warn You are the root user, must be a regular user."

# Current DPMS times (in minutes)
dispdpms=$(xset -q | grep "DPMS is" | awk '{ printf $3 }') # Enab. or Disb.
dispstand=$(xset -q | grep "^  Standby: " | awk '{ printf $2/60 }')
dispsusp=$(xset -q | grep "^  Standby: " | awk '{ printf $4/60 }')
dispoff=$(xset -q | grep "^  Standby: " | awk '{ printf $6/60 }')
dispblank=$(xset -q | grep "^  timeout:  " | awk '{ printf $2/60 }')

# Resume time in hours
resumetimehr=$(echo "scale=1;${resumetime}/60" | bc)

# Display help
case $1 in
  -h | --help | h | help )
    # Help message.
    echo "  $prog disables screen blanking and screensaver to allow viewing a video.  Running the program again will enable them.  If the 'resumetime' variable is set after that time $prog will resume normal powersaving values." | fmt -c -w 76

    # Display current values of power management and movietime.
    suspinhtest=$(ps aux | grep -v grep | grep $suspinhscript)
    suspinhval=$([ -n "$suspinhtest" ] && echo "Disabled" || echo "Desktop settings")
    # DPMS disabled information
    echo "   ${txtbld}Current settings ${txtrst}(in minutes, 0 = disabled):"
    if [[ "$dispdpms" == "Disabled" ]]; then
      echo "   DPMS:         $dispdpms"
      echo "   Suspend:      $suspinhval"

    # DPMS enabled information
    if [[ "$dispdpms" == "Enabled" ]]; then
      echo "   DPMS:         $dispdpms"
      echo "   DPMS times:   Blank: ${dispblank}; Standby: ${dispstand}; Suspend: ${dispsusp}; Offtime: ${dispoff}"
      echo "   Suspend:      $suspinhval"
    echo "   ${txtbld}$prog settings${txtrst}:"
    echo "   Resume after: $resumetimehr hours"
  [a-g,i-z,A-G,I-Z,0-9,-]* )
    echo " Use '-h' for help"

# Suspend inhibit script (must be run as seperate process)
suspinhibit () {
    echo '#!/bin/bash
    for time in $(seq 1 '$resumetime'); do
    # Simulate user activity every minute
    dbus-send --print-reply --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
    sleep 60

# Toggle powersaving
if [[ "$dispdpms" == "Enabled" ]] && [ -z "$suspinhtest" ]; then
  # Disable blanking, screen power saving
  xset s off; xset -dpms
  # Create script in tmp
  suspinhibit > "$suspinhscript"
  # Make script executable
  chmod u+x "$suspinhscript"
  # Run script
  nohup "$suspinhscript" &> /dev/null &
  echo "$pass $prog started, powersaving disabled."
  # Enable blanking, screen power saving
  xset s on; xset +dpms
  # Kill script
  if [ -n $suspinhtest ]; then
    echo "$info $prog stopped, powersaving enabled."
    kill -s 9 $(pgrep movietime-susp) &> /dev/null

Turn off all cellphones and enjoy the show!


Get every new post delivered to your Inbox.

Join 52 other followers