PDA

View Full Version : Custom Screenlets Manager script with cli mode (now screenletsd in whise's branch!)


some-guy
January 24th, 2008, 08:23 PM
I didn't want to annoy whise about it anymore so I made a bash script to replace /usr/bin/screenlets-manager :D

Options:
--gui Open up the Graphical Interface
--cli Use the Command Line interface
Cli Options (only use one at a time):
run Run the Screenlet
au Add the Screenlet to your autostart list

Source
#/bin/bash

runDaemon()
{
if [ -z "`ps -f -C python | grep screenlets-daemon`" ]; then #Check if Daemon is running
echo "Loading Daemon" #Load Daemon
/usr/share/screenlets-manager/screenlets-daemon.py > /dev/null &
else
echo "Daemon is already running"
fi
}

startgui()
{
exec /usr/share/screenlets-manager/screenlets-manager.py $@ #Load Gui
}

findScreenlet()
{
screenlet="$1"

#find new screenlet
if [ -e $HOME/.screenlets/$screenlet/`echo -en $screenlet`Screenlet.py ]; then #Check in /usr/share/screenlet
location="$HOME/.screenlets/$screenlet/`echo -en $screenlet`Screenlet.py"
elif [ -e /usr/share/screenlets/$screenlet/`echo -en $screenlet`Screenlet.py ]; then #Check in ~/.screenlets
location="/usr/share/screenlets/$screenlet/`echo -en $screenlet`Screenlet.py"
else
echo -e "There is no screenlet named $screenlet"
exit 1
fi
}

auScreenlet()
{
AU_DIR="$HOME/.config/autostart" #Autostart folder
echo -e "[Desktop Entry]" > $AU_DIR/`echo -e $1`Screenlet.desktop #Make a .desktop entry to autostart the screenlet
echo -e "Name=`echo -e $1`Screenlet" >> $AU_DIR/`echo -e $1`Screenlet.desktop
echo -e "Encoding=UTF-8" >> $AU_DIR/`echo -e $1`Screenlet.desktop
echo -e "Version=1.0" >> $AU_DIR/`echo -e $1`Screenlet.desktop
echo -e "Exec=$location > /dev/null" >> $AU_DIR/`echo -e $1`Screenlet.desktop
echo -e "X-GNOME-Autostart-enabled=true" >> $AU_DIR/`echo -e $1`Screenlet.desktop
}

runScreenlet()
{
$location > /dev/null & #Run Screenlet
}

help_me() #Help
{
echo -e " Options:"
echo -e "\t --gui \t\t\t Open up the Graphical Interface"
echo -e "\t --cli \t\t\t Use the Command Line interface"
echo -e " Cli Options (only use one at a time):"
echo -e "\t run \t\t\t Run the Screenlet"
echo -e "\t au \t\t\t Add the Screenlet to your autostart list"
}

if [ x$1 == x"--gui" ]; then #Decide what to do
runDaemon
startgui $2 $3 $4 $5 $6 $7
exit 0
elif [ x$1 == x"--cli" ]; then
if [ x$2 == x"run" ]; then
findScreenlet $3
runScreenlet
exit 0
elif [ x$2 == x"au" ]; then
findScreenlet $3
auScreenlet $3
exit 0
else
help_me
exit 1
fi
else
help_me
exit 1
fi

Download here (http://somelinuxguy94.googlepages.com/screenlets-manager.tar.gz)

I could make a more proper way of loading the screenlets, where it would store a config somewhere and only have 1 entry in autostart, but I wanted to follow the method the 'real' screenlets-manager follows :D

whise
January 24th, 2008, 09:00 PM
pretty neat do you want me to include it in the core? ill replace screenletsd with this?

some-guy
January 24th, 2008, 09:08 PM
if you want, but I was thinking that if it was going to be in the core, why not mod screenlets-manager to put auto start options in somewhere like ~/.config/screenlets.lst or something. Then I can mod this script to be able to read/write that file and load all of them at once which will also make allow having only one entry for all screenlets :D

so all it needed to contain would be the path to the screenlets, like
/usr/share/screenlets/WallpaperClock/WallpaperclockScreenlet.py
~/.screenlets/SmoothWeather/SmoothWeatherScreenlet.py
...

whise
January 24th, 2008, 09:14 PM
why would you like to load all the screenlets at once?

some-guy
January 24th, 2008, 09:19 PM
good question...
I guess there is no reason :p
never mind, yeah you can include it as it is :D
Maybe its time I upgrade to your branch :D
EDIT: Just upgraded, much better than before :D

whise
January 24th, 2008, 11:01 PM
done ... nice job , ill update the credits later