Tag Archives: bash

Batch change color of SVG icon set

CC-SA 3.0
Iconset in LM3

I ran across this cool set of icons that can be used in home automation projects. The latest firmware from openrb allows me to use SVGs as Icons in the logic machine re:actor. Only drawback is that for each state I would like to change the color of the icon. The iconset is set in white as default color.

When you open any of the SVGs from the KNX User Forum you will find that the color is set as a standard #000000 HTML color value for white. All we would need to do is switch these from that to for example #FFFFFF for them to be black. To do this on one file the code would be:
sed -i -e's/\"#.\{6\}/\"#000000/g' -e 's/#.*;/#FFFFFF;/g' icon.svg

where icon.svg is the file we want to turn into black lines.

If we then want to change all, we need a small bash script to loop all the files in a directory and apply the change. That would look like this:
for f in *.svg;
do
echo "Changing color of $f ..."
sed -i -e's/\"#.\{6\}/\"#000000/g' -e 's/#.*;/#FFFFFF;/g' "$f";
done

It is a good Idea to rename the files with a prefix that describes the color. That way you will have them sorted by color in the logic machine. Just change Black to any color you have chosen.
for f in *.svg ; do mv "$f" "Black $f" ; done

The logic machine likes the files to be zipped if you are going to upload a batch. I used this command to generate it:
zip black.zip *

Now you can go into the logic machine and upload black.zip.