Bash Scripts, Elementary OS, Linux

Updated Desktop Slideshow script for ElementaryOS

ElementaryOS logo A few days ago I released a desktop wallpaper slideshow script for ElementaryOS. A user pointed out that it wasn’t changing the login screen wallpaper. I added a fix and now your login screen will have a random background; the same one as the desktop slideshow. If there is a big demand for them to be independant of eachother I may make the desktop slideshow differ from the login screen.

You can still use the -bootonly flag to only set only one random wallpaper once when you log in to ElementaryOS. This will now also change your login screen’s wallpaper.

If you rather not change the login screen background from the default ElementaryOS one you can use the –nologin flag.

To change the login screen you will need qdbus. You can install it with apt-get install qdbus.

I added a bunch of logging which is useful if you give the desktop slideshow script a large number of files to work with. Occasionally you may see an x on your desktop indicating that an image couldn’t load. You can then check the logs with tail -f /var/log/syslog and see what image is giving you issues. Then you can delete it or move it. You must enable logging with the –log flag for this to work.

As always you can get the wallpaper slideshow script from Github. Check out the last post for more information on installing and running the Wallpaper Slideshow script. Let me know if you encounter any issues. Its always good to hear feedback.

Bash Scripts, Linux

Get the size of your BTRFS Snapshots

If you want to get the size of your BTRFS snapshots you would probably use btrfs qgroup show.  This only shows you a list of IDs and the sizes are in bytes. I wrote a script that will convert the sizes from bytes to kilobytes, megabytes or gigabytes. It will combine the IDs with the name of each snapshot or subvolume from btrfs subvolume list to make each row a lot more meaningful.

In the end instead of seeing a list like this:
Screenshot from 2015-05-26 15:47:24

You’ll see:

Detailed information of each BTRFS snapshot
Detailed information of each BTRFS snapshot

Instead of meaningless IDs you now have the name of your BTRFS subvolumes or snapshots. Instead of a hard to decipher string of bytes it converts each amount into the most appropriate unit of measurement. You can also see the total amount of data that is being used by the snapshots.

For this to work you first need to enable  quotas. Run this command to enable quotas if you haven’t done so already:

sudo btrfs quota enable /

You can clone the project from github by running:
git clone https://github.com/agronick/btrfs-size.git

Or you can just go a wget on the script:
wget https://raw.githubusercontent.com/agronick/btrfs-size/master/btrfs-size.sh

Set it to executable with:
chmod +x ./btrfs-size.sh

Now you can just run the script with: ./btrfs-size.sh

All the columns are pretty self explanatory. The Total column will tell you how much data is in that BTRFS subvolume. The Exclusive Data column is how much data is exclusive to that subvolume. Since BTRFS is a “copy on write” filesystem none of the data is replicated when you create a snapshot. It only needs to make a copy when something changes.

Leave your feedback here to let me know how it worked for you.

Linux

Debugging Vala programs in an IDE

Geany

Geany is an IDE the supports a number of languages including Vala. This tutorial will show you how to get the debugger plugin for Geany working with Vala code. At the time of this writing the plugin in the Ubuntu repositories happens to be broken. We’ll install it from source and configure it for Vala. If you don’t use Ubuntu or a derivative like Elementary OS this article should still be applicable. You just might need to change a few things.

Installation

You can install Geany with:
sudo apt-get install geany

There is a package called geany-plugin-debugger. You can try installing it. At the time of this writing its broken. It installs to the wrong location. If you copy the files to the right location it causes a segmentation fault as soon as you enable it. This was reported half a year ago: https://bugs.launchpad.net/ubuntu/+source/geany-plugins/+bug/1354747

Instead you can get all the plugins for Geany off Github. At the current time the version of Geany in the Ubuntu repos is 1.24. All we care about is the debugger but the other ones are nice to have. I removed the ones from the build script that won’t compile on 1.24 and forked it. You can get it using this command:
git clone https://github.com/agronick/geany-plugins.git

If you have Geany 1.25 grab the offical one:
git clone https://github.com/geany/geany-plugins.git

You need autotools to compile it. Just do sudo apt-get autotools 

Now to install it just do:
./autogen.sh
make -j PROCESSORS #Replace PROCESSORS with the number of processor cores your computer has or the number of jobs you want to spawn to compile
sudo make install

Hopefully this worked. If you get an dependency error install whatever dependency is missing.

Now open up Geany. If you go to Tools > Plugin Manager you should be able to enable the debugger. It wont work just yet though. There are a few more things you need to set up.

Configuration

At this point you’ll want to create a new project. Now you’ll need to set the build parameters. Go to Build > Set Build Commands.

Set this under Vala Commands:

Label Command
Compile valac -c "%f"
Build valac -g --save-temps --pkg gtk+-3.0 "%f"

You can remove the –pkg gtk+-3.0 part if you don’t want to build GTK apps.

Now you will need to do the following:

  1. Insert a breakpoint in your Vala program
  2. Click the build icon
  3. Open the debugging view
  4. Browse for the executable it created
  5. Run your Vala program

Steps for debugging
 There you go. You now have a working Vala debugger. You can step through the code and look up variables at runtime right in your IDE. I hope this helps and is useful. I know I was looking for it for a few months. Its nice to finally have.

I also made this video on how to debug segmentation faults in a command line:

Elementary OS, Linux

Elementary OS Slideshow Wallpaper

Elementaryos logo I set out to code a lightweight script that will make your desktop background change at a preset interval. It changes the background with a fade turning your wallpaper into a slideshow. Having a desktop slideshow seems to be a desired feature in Elementary OS and this method does it using hardly any memory. This should work on any Gtk based distro but I’ve only used it on Elementary OS. Even if you don’t want a slideshow you can use the script to load a random background on each boot up or whenever you run the script. Just use the –bootonly option.

You can find the script on my Github or do a simple wget put the script wherever you want:

wget https://raw.githubusercontent.com/agronick/Wallpaper-Slideshow/master/wallpaper_slideshow.sh

Once it is saved just set it to executable with:

chmod +x ./wallpaper_slideshow.sh

There are a few parameters you can use:

Usage: ./wallpaper_slideshow.sh [FOLDER] [MINUTES]…

  • [FOLDER] Set a folder with images. If it has other files they will be ignored.
  • [MINUTES] (Optional default:2) Set the number of minutes that you want to wait before changing to the next image.
  • [–bootonly] Set this if you want to change to a random image on boot and then exit.
  • [–wait] Do a delay of however minutes you set MINUTES to before switching to the first image.
  • [–log] Display information to the console and log it to syslog.
  • [–help] Display a help message and then exit.

If you just want to see it cycle the default Elementary OS wallpapers every two minutes run ./wallpaper_slideshow.sh without any parameters.

Here is a sample command: ./wallpaper_slideshow.sh ~/Pictures/Backgrounds/ 2 --log

Once you found a setup you like you can append –makecmd to show you a command you can copy and paste into Elementary OS’s startup application settings.

Setting it up for startup in Elementary OS
You need to go to Applications > System Tools > System Settings > Applications > Startup

Elementray OS Startup Applications

Once there click the + in the bottom left. You can then paste the command given to you by –makecmd in the highlighted box.

That’s it. You’ll now have a slideshow wallpaper on your desktop. The script is programmed to load a random set of images and display them as desktop wallpaper sequentially. When it gets to the end it will shuffle the list and start displaying from the beginning.

Update: If you’ve downloaded in the past you probably want to redownload. Elementary OS wasn’t killing the script when it ended a session. Now the script will kill itself if it spends 10 minutes disconnected to a desktop.

Update2: The script now supports changing your ElementaryOS’ login screen. There is a post detailing the changes.

If you are looking for a great collection of wallpaper you can find one here: http://chromecastbg.alexmeub.com/ Click Download in the top right to get them all.