Another wallpaper changer for Gnome and Unity

The previous wallpaper changer that I wrote in Python served me well for the last 2 years, but sometimes it would get stuck with some wallpapers: of the 200 pictures I have in my wallpapers folder (mostly taken from the paper wall), some were definitely being shown more often than others. Has the script developed a taste? Probably! 🙂

So this time I decided to put together something very quick, but that does a better job at never showing the same picture twice before all pictures in the folder have been set as desktop background.

It comes as a single bash script, there’s no configuration file to set, it picks pictures from a single folder (whereas the Python version could use several), and it moves files to a folder called shown when setting them as desktop background. Not very elegant, but it gets the job done!

Here it is; you can set your wallpapers folder and the refresh interval at the highlighted lines.

#!/bin/bash
#
# WallpaperChanger.sh
# Copyright 2014 Michele Bonazza michele@michelebonazza.com
#
# A simple script to automatically change your wallpaper in Gnome.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

WALLPAPERS_FOLDER=/home/path/to/your/wallpapers
REFRESH_INTERVAL=$((5 * 60)) # change every 5 minutes
MODE="zoom" # one between none, centered, wallpaper, scaled, stretched, zoom, spanned

# Changes the desktop background, and moves it to the "shown" folder so that it's
# not shown again before all wallpapers in the folder have been used.
# arg1 the file name of the file to be set as new background; must be in the
#      current folder
function change_wallpaper() {
  mv $1 shown
  gsettings set org.gnome.desktop.background picture-uri file://$WALLPAPERS_FOLDER/shown/$1
  gsettings set org.gnome.desktop.background picture-options $MODE
}

# Echoes the next wallpaper to be set, picked at random among images in the
# configured folder
function get_next_wallpaper() {
  find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg"| shuf -n 1
}

mkdir -p $WALLPAPERS_FOLDER/shown
cd $WALLPAPERS_FOLDER

while true; do
  NEXT_WP=$(get_next_wallpaper)
  
  # have we used all wallpapers?
  if [[ "$NEXT_WP" == "" ]]; then
    # yes, chdir to shown, and move them all back to the parent folder
    cd shown
    # move them to parent folder
    find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg" | xargs mv -t ..
    cd ..

    # check again
    NEXT_WP=$(get_next_wallpaper)

    if [[ "$NEXT_WP" == "" ]]; then
      echo "no wallpapers found in $WALLPAPERS_FOLDER, will check again in $REFRESH_INTERVAL seconds..."
      sleep $REFRESH_INTERVAL
      continue
    fi
  fi
  
  echo "changing background to $NEXT_WP"
  change_wallpaper $NEXT_WP
  sleep $REFRESH_INTERVAL
done

As always, I’ve also added this to my pastebin.

Save it as wallpaper_changer.sh, make it executable

chmod +x wallpaper_changer.sh

and add it to your “Startup applications” list, which can be found in Ubuntu’s main menu (the one you use to log out/shut down the computer), or can be brought up from a terminal using

gnome-session-properties

Click “Add”, use whatever name you want and browse to the wallpaper_changer.sh script (wherever you’ve saved it).

Sometimes I found that “Startup applications” doesn’t work: make sure that after having added your script and closed the window you can see an entry called wallpaper_changer.sh.desktop in the output of

ls -l ~/.config/autostart

If it’s not there, remove the entry and try again (I know, I know. The alternative is to fiddle with Upstart or init.d so if you want a GUI, that’s better than nothing!)

You can also change the effect to apply to your wallpapers at line 23 in the script.

Enjoy your new desktops! 🙂

Disable touch input for a Wacom Bamboo tablet using a Unity launcher (or a Gnome launcher)

I love my Wacom Bamboo graphics tablet, and I really appreciate the fact that it just works in Ubuntu. Palm rejection sort of works, but that “sort of” drives me crazy when I’m using the pen and trigger scrolling by resting my hand on the tablet. I couldn’t find a quick way to disable touch input, something that I can do from a nice GUI window in Mac OS.

After searching some tool to do that, I found the very powerful xsetwacom command, and wrote a very simple script that enables/disables touch.

It goes like this:

#!/bin/bash

DEVICE_ID=$(xsetwacom --list devices | grep TOUCH | egrep -o "id\: [0-9]+" | cut -d" " -f2)

if [[ "off" == $(xsetwacom get $DEVICE_ID touch) ]]; then
    xsetwacom set $DEVICE_ID touch on
else
    xsetwacom set $DEVICE_ID touch off
fi

(should have used awk @line 3, but sometimes I get lazy when writing silly scripts)

Save this file on your user’s home calling it wacom_toggle_touch and make it executable (chmod +x wacom_toggle_touch).

Everytime you run the script, it toggles touch on the tablet. Very neat. But I wanted to just have a graphical button to click, so I created a gnome launcher that just does that; here it is:

[Desktop Entry]
Encoding=UTF-8
Name=Wacom Bamboo Touch
Comment=Toggles touch on a Wacom Bamboo Tablet
Exec=/bin/bash "/home/myuser/wacom_toggle_touch"
Icon=/usr/share/icons/Faenza/devices/scalable/input-tablet.svg
Categories=Application;
Version=1.0
Type=Application
Terminal=0

Name this file wacom-toggle-touch.desktop (the .desktop part is important) and save it to either /usr/share/applications/ or ~/.local/share/applications/, depending on whether you want all users to access the script or only your current user.

I use the cool Faenza theme for my icons, so that explains the icon path @line 6. Here’s the icon if you don’t want to use the theme but you’re looking for an icon that just gets the job done. Download it to some folder and update the path accordingly in the launcher. Also, be sure to update the path to the script @line 5 (for some reason using ~ for your user’s home doesn’t work, you have to type the extended /home/your_username path).

When you’re done, drag the wacom-toggle-touch.desktop file to your Unity bar (I actually use Docky instead, it makes switching between Mac OS and Ubuntu a lot easier on my poor brain) and just click it everytime you want to toggle touch mode!

The same process should work for Gnome as well, just drag the .desktop file to wherever launcher bar you want (assuming Gnome still has launcher bars, they kind of lost me after Gnome 3 so I don’t know).

Play the System Bell as shell commands end in Ubuntu/Debian

This is a nice little trick I started using after switching to Gnome3, as I don’t have the application switcher panel any longer: before, I could put my mouse cursor over that to see a preview of shell windows where a command is running.

Now I should keep moving the cursor to the top-left corner and wait for the animation to show all open windows, which is tedious when you don’t have a precise idea of how long will commands take.

So, the long hated system bell sound comes to rescue!

Just append ; echo -e "\a" after the command you want to run and… voilà, you’re in the event-driven world! 😛

Example:

wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.13.tar.bz2; echo -e "\a"

This command of course won’t do anything if your volume is set to 0 or you explicitly disabled system audio notifications.

Change color scheme in Geany

After trying Sublime for a while, and quite liking it, I found myself in the middle of a deep customization of the editor… to make it work like Geany!

For quick editing of local bash/python scripts or configuration files there’s no editor that meets my taste better (I said local cause when dealing with remote files my all-time favorite is vim).

The one thing that I like more in Sublime than in Geany is its look: it’s very elegant, but in the end what I really missed in Geany was a dark editor theme.

I discovered this project on GitHub with several available themes, very easy to install (as in execute-install-script-with-no-options) but.. not that easy to choose from Geany’s interface!

[Update – Mar13] – unjordi posted a nice command line one-liner to get and install the geany-dark color schemes, here it is:

wget -qO- http://geany-dark-scheme.googlecode.com/files/geany_dark_filedefs_20100304_190847.tar.bz2 | tar jxv -C ~/.config/geany/filedefs/

After you’ve downloaded the color schemes and before editing the configuration file as described here below try to restart Geany and check if there’s an entry under View/Editor>Color Schemes>; if it’s there you can choose among all installed color schemes from a nice list! 🙂

If you’re out of luck (no list for you) you must edit Geany’s configuration file ~/.config/geany/geany.conf and find the color_scheme line. You must specify the whole file name of the color scheme you wish to use, without its path (it must be in the ~/.config/geany/colorschemes folder anyway).

So, to set your theme to tango-dark you shall have this line in your geany.conf file:

color_scheme=tango-dark.conf

Restart Geany and there you have your nice dark theme 🙂

[Update – Nov13] – a reader had troubles with the configuration file (always reverting to its original state, or not being read correctly by Geany), scroll down to November 5 2013 in the comments if you have the same issues!

Remove the “file edit view go bookmarks help” entries from the Gnome 3 top panel

After running the usual apt upgrade the nautilus menu items suddenly appeared below gnome-shell’s top panel. By below I mean that I have a transparent top bar under which the menu items are showing, but can’t be clicked at all.

Following this post (scroll down to the “Fix Nautilus menu being displayed under the GNOME Shell top bar when using transparent GNOME Shell themes” paragraph) I managed to remove them by simply going to the gnome tweak tool and disabling the Have file manager handle the desktop option under Desktop.

I don’t even know why that option has been set on in the first place…

[Edit]: when disabling the Nautilus desktop management option not only icons will disappear from the desktop, but you you won’t be able to right-click and execute scripts either (and with gnome-shell being very unstable with the latest ATI drivers I very often rely on my gnome-shell restart script, so this is a show stopper).

The only solution I found (and I actually had to struggle a bit, since it doesn’t seem to be a very common issue yet) is to set the top panel background to some opaque image or gradient. Since I installed a gnome-shell theme (you can find the option in the gnome tweak tool under Theme/Shell theme) called Nord, the CSS files to be edited can be found inside ~/.themes/Nord/gnome-shell/, and all styles for the top panel are defined in ~/.themes/Nord/gnome-shell/panel.css.

If you don’t have a custom theme you’ll find the top panel background definition in a file with a path like /usr/share/themes/Ambiance/gtk-3.0/apps/gnome-panel.css (change Ambiance with the name of the GTK+ theme you use).

You must find the #panel definition, and change the background- tags to set an alpha (the fourth in rgba values) of 1.0 like I did:

#panel {
    border: 1px solid rgba(0,0,0,0.2);
    background-gradient-direction: vertical;
    background-gradient-start: rgba(84,84,84,1.0); /* note the 1.0 value */
    background-gradient-end: rgba(168,168,168,1.0);
    /* and so on... */
}

Set fullscreen windows to go over gnome-shell’s (and Unity’s) top panel (top bar) with python/C++ and Glade

I know that there’s a function called fullscreen() that you can call on a window to set it fullscreen. I also know that my screen resolution is 1920×1080, so I supposed that explicitly setting the window’s height and width to the exact screen size would have forced mutter to put my window above everything else.

But…

No, it doesn’t. There’s a sneaky little option called Window Type that has to be set to Popup to make gnome’s top bar surrender and let your window dominate the screen. You can find it in the General tab in Glade (it’s the third field in Glade 3.10.0, I don’t know about the other versions).

Is this some kind of common knowledge that doesn’t have to be put on tutorials? I find the lack of documentation on GTK+3 disturbing.. 🙂 (I know that the API is quite well documented, but we’re still missing the plethora of examples you can find for GTK+2 on the web)

Make your own picture-changing wallpaper in Gnome3

[Edit – April 2014]: I noticed my python script here didn’t do a very good job at not showing the same wallpaper twice before all wallpapers in a folder were shown. Hence, I created another simpler version of the script in bash that does a better job at that. You can find it here

I hoped Gnome3 would have had an integrated function to create custom wallpapers that change throughout the day by picking a folder with your images and choose some refresh interval, but still you have to rely on external scripts or programs.

I’ve been using WallCh for quite some time under Unity, and it suited me well. It was a bit too much for what I wanted to actually do, grabbing pictures in a folder and set them as wallpaper every 3 minutes that is.

Another thing that “annoyed” me is that while in Unity minimized windows are quite the same thing as background processes — in that they just stay on the Unity dash and as long as you don’t hit Alt+Tab they never show up — in Gnome3 I very often go through the list of all open applications, and WallCh by default is always there. I’m not a fan of Alt+Tab in Gnome3: I find it faster to hit Super with my left hand and click on a window I instantly recognize with my right hand than to cycle through small pictures with titles. I don’t know whether WallCh has an option to run in the background, but if it does I didn’t instantly find it and I opted for a little DIY 😛

That being said I thought that surely a simple command must exist to just change the wallpaper, and it does! It’s gsettings, with its org.gnome.desktop.background keys. So, to set your ~/Images/1080p/wall_0.png as background you just call

gsettings set org.gnome.desktop.background picture-uri file://$HOME/Images/1080p/wall_0.png
gsettings set org.gnome.desktop.background picture-options zoom

you can just add these two system calls in some simple script in whatever language you like and there you have your custom wallpaper changer!

I came up with a simple python script which is actually a stripped-down version of this nice little script by Romano Giannetti. I simply removed all verbosity and moved the pictures folder definition to a properties file that is checked at every interval, so I never have to change the script itself. If anyone is interested, I’ll post it (it’s less than 50 LOC in the end).

Then, I added the script as a startup application with gnome-session-properties so I finally have my lightweight background wallpaper changer 🙂

Edit: as Romano himself asked for it, here’s my version of the script: http://pastebin.com/embed_iframe.php?i=UGYNi0K5

Well, if truth be told my version of the script has no error checks whatsoever, but since somebody may try to use this I thought that some information on what’s going on may be helpful. You can list several folders in the configuration file; if you change the configuration file while the script is running the list gets parsed again and reset.

Gnome3 (gnome-shell) is very slow using latest ATI Catalyst Drivers

Well, the 12.1 upgrade (Jan 25) at least made Gnome3 usable… The tearing and bad rendering seen with fglrx have finally gone but everything is painfully slooooooooooow.

Two things helped me get an almost responsive desktop, and I don’t know which one actually did the trick. They should actually do the same thing, but who knows?

The first thing I did is to go to the Catalyst Control Center and disable both Vsync (under 3D section) and Tear-Free (under Monitors) options. That seemed to give a little boost to the overall responsiveness of my desktop, but another thing I found out from a comment to a bug report on ATI’s bugzilla is to add this little magic line to your /etc/environment file:

export CLUTTER_VBLANK=none

This should be the equivalent for disabling the Vsync option from the Catalyst Control Center, I guess, but after rebooting everything seems to run a lot more smoothly!

Eclipse crashes on startup with Gnome3 on Ubuntu 11.10

Speaking of Gnome3 choices, I really like the whole CSS-ish management of themes: I’m sure it’ll help in making the gnome-look community grow with a number of experienced web developers who won’t have to struggle too much to deliver great-looking themes.

Once again, I think that at this moment we’re not quite there yet.

Not liking the fat-ass default title bar that Gnome3 comes with, I switched to the sleeker Adwaita Dark theme (the link to the developer’s website doesn’t seem to talk about it?) and I’m fine with it.

On an apparently completely unrelated front, Eclipse started to crash on startup, with no error messages logged on workspace/.metadata/.log, no errors on ~.xsession-errors, no errors on the shell! The splash screen would show up, no progress bar would ever come up, and it’d stay forever like that (sometimes with a java process taking up to 100% of CPU, sometimes not).

Out of plain desperation, I went for a shy export GDK_NATIVE_WINDOWS=1 on the shell script that I use to launch Eclipse and… guess what? It worked! 😀

I use an external script to choose one of the installs of Eclipse I have (Helios J2EE, Helios CDT, Indigo.. so I have /usr/bin/helios, /usr/bin/cdt and /usr/bin/indigo), but for what concerns this issue it may come down to this:

#!/bin/bash
export GDK_NATIVE_WINDOWS=1
./eclipse

But then I thought… surely the theme I just installed has nothing to do with this issue, right? Well, I was sadly wrong. Using Gnome Tweak Tool (I don’t understand why this does not come with Gnome by default) I figured out that switching the GTK Theme back to default (Adwaita, but not dark) Eclipse runs fine without the GDK_NATIVE_WINDOWS variable set! And I can keep the Adwaita Dark windows decoration theme!

Another step towards XFCE I managed not to take.. Gnome3, don’t fail me, I’m trying hard to like you! 🙂

Add a simple restart Gnome Shell script to your right-click menu

After using the behated Unity for too much time I decided to give Gnome3.2 another chance; last time I tried I couldn’t get my cheap integrated Radeon 3000 graphic card to work with all the rendering gnome-shell requires, so I had to pick one of Gnome “classic” or Unity2D. The latter is a little less ugly, albeit suffering from too much rigidity in what you can customize and what you cannot. I tried to like it, I really did, but working with the left dash bar is painful to me.

So, after installing the latest catalyst drivers (12.1) from ATI I’ve been able to use Gnome3, and after tweaking it hard with several extensions (nice system, by the way, but maybe support for browsers other than firefox would help) I now have a desktop that I kinda like. It’s sad that I used to like Gnome2 better, though.

Not speaking of its slow responsiveness (I admit my GPU is no monster, but my PC is 10 months old, so I’d expect it to run whatever window manager… heck, it runs KDE 4 just fine!), what I find astonishing is its instability. Every now and again, gnome-shell screws up for whatever reason, and all window controls are gone, top bar and the gnome-shell itself as well. Switching to another tty with Ctrl+Alt+F1 and logging in with my user to killall gnome-shell is not helping since the gnome-shell process lies in the other session that I’m therefore forced to kill, restarting the gdm process.

At first I used this little hack from phreaknerd’s blog: you schedule a script for automatic execution that checks whether a “delete me if you want to restart gnome-shell” file exists every 15 seconds (so the routine was like: gnome-shell dies, switch to tty1, login, rm polled file, logout, Ctrl+Alt+F7 back to graphic session, wait for the script to find out).

But then I grew tired of waiting the 7.5 seconds (on average :P) for the script to detect that the control file is missing, and of the whole tty switching in general; since I’m always able to right-click on the desktop (if anything on the empty space left by the gone window decorations) I think a better solution is to add a simple script to ~/.gnome2/nautilus-scripts/ (why is it still called gnome2 anyway) like this:

cd ~/.gnome2/nautilus-scripts/; echo -e '#!/bin/bash'"\n"'gnome-shell --replace' > Restart\ gnome-shell; chmod a+x Restart\ gnome-shell

So now all I have to do is right click somewhere on the desktop, choose Scripts/Restart gnome-shell and I can get back to work! 😀

I really, really, really hope that 3.4 will be a lot more stable though…