Created
May 25, 2018 12:50
-
-
Save skyecodes/5ed5c7dc59f011aa9f89c0e672e9125c to your computer and use it in GitHub Desktop.
visualizer.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#======================================================================================= | |
# | |
# Transforms cava music visualizer in a cool desktop decoration | |
# | |
# Author: Guido_Fe | |
# | |
# Dependencies (and credits): | |
# xdotool | |
# cava | |
# URxvt | |
# devilspie | |
# | |
# Usage: | |
# | |
# To start, execute this script. To stop, execute this sctipt again. | |
# | |
# Description: | |
# | |
# This script starts the cava music visualizer on a transparent backround through URxvt | |
# ('cause it's easy to customize and support transparent foreground and background). It | |
# then uses devilspie to strip it of his window decorations and rules, move it to the | |
# right place and resize it. | |
# Problem: the panel doesn't allow you to focus the windows below it. | |
# My solution: move cava under the screen when the mouse pointer go over | |
# it, and reset its position when I move the pointer away. I accomplished this | |
# behavior with xdotool. | |
# | |
#======================================================================================== | |
#============= | |
# PARAMETERS TO SET | |
# | |
# Remember to don't leave spaces before and after the equal symbol | |
# X value of the screen resolution | |
Xscreen=2560 | |
# Y value | |
Yscreen=1440 | |
# Offset applied to the window's vertical position | |
offset=15 | |
# Height of the cava panel | |
h=250 | |
# If you want to use a different cava config, set this parameter to the respective path or | |
# leave '' if you don't want to change it | |
cavaConf='' | |
# Set these parameters if you want to transform a default terminal color to another one. | |
# This is useful if you want to have semitransparent cava bars. To do so, first set the | |
# cava bar colors to a default one, different to the background (white, red, green...), | |
# form the cava config file, and assign it's color number to the inColor variable. | |
# The numbers are: | |
# | |
# black='0', red='1', green='2', yellow='3', blue='4', magenta='5', cyan='6', white='7' | |
# | |
# then set the outColor variable to the color you | |
# want. Examples: inColor='2' outColor='[80]#223454', where 80 is the alpha level. The | |
# alpha level can be '0' (fully transparent), '100' (fully opaque, or a value in between. | |
# For outCol you can also use normal color definitions, like '#223454'. | |
# As usual, leave both blank ('') if you don't want to set them. | |
inCol='5' | |
outCol='[80]#fd971f' | |
#============= | |
# Process parameters | |
if [ ! $cavaConf = '' ]; then | |
cavaConf=" -p $cavaConf" | |
fi | |
if [ ! $inCol = '' -a ! $outCol = '' ]; then | |
inCol=" --color$inCol" | |
outCol=" $outCol" | |
else | |
inCol='' | |
outCol='' | |
fi | |
#Check if it's already running | |
if [ "$1" = 'stop' ] || [ "$1" = 'restart' ]; then | |
if [ `cat /tmp/processesToKill 2> /dev/null | wc -l` -ne 0 ]; then | |
#Kills the processes of the other instance and itself | |
echo "Stopping..." | |
kill -15 `cat /tmp/processesToKill` > /dev/null 2>&1 | |
rm /tmp/processesToKill | |
fi | |
fi | |
if [ "$1" = 'start' ] || [ "$1" = 'restart' ]; then | |
echo "Starting..." | |
#The core of the program | |
echo $$ >> /tmp/processesToKill | |
#Write the conf file for devilspie | |
echo '(and | |
(is (window_name) "cava") | |
(is (window_class) "URxvt") | |
(begin | |
(stick) | |
(below) | |
(pin) | |
(undecorate) | |
(skip_pager) | |
(skip_tasklist) | |
(wintype "desktop") | |
(geometry "'$Xscreen'x'$h'+0+'`expr $Yscreen - $h + $offset`'") | |
) | |
)' > /tmp/cava.ds | |
#Start urxvt and execute cava in it. Change the color white to the one chosen | |
urxvt -bg "[0]red"$inCol$outCol -b 0 -depth 32 +sb -e cava$cavaConf & | |
wPid=$! | |
echo $wPid >> /tmp/processesToKill | |
# Starts devilspie, that will move and resize the window | |
devilspie /tmp/cava.ds > /dev/null & | |
echo $! >> /tmp/processesToKill | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment