topic title: slim background
Posts: 1,081
OU812
Joined: 29 Sep 2007
#1
Hello. I wrote the script that changes slim's background image. Here's the problem: If a user does not enter the root password correctly, the background image will not be changed. However, the dialog still pops up and announces that it has been changed. How do modify the code to prevent this mistake? Thanks.

Code: Select all

#!/bin/sh

cd $HOME/Wallpaper/

slim_background=`zenity --file-selection --title="Select a Background"`

if [ $? = 0 ] ; then
  zenity --question --text"Set as new background?"

  if [ $? = 0 ] ; then
    wterm -tr +sb -fg white -T"System" -e su -c"cp -bv \"$slim_background\" /usr/share/slim/themes/antiX/background.jpg"
  
    zenity --info \
      --text="Background Changed.\nPlease Logout/Login see changes."
  fi
  
fi
john
Posts: 1,520
eriefisher
Joined: 07 Oct 2007
#2
Take a look at the first few lines of remaster.sh. It should help to figure it out. It check for root and fails if you are not.
Posts: 1,081
OU812
Joined: 29 Sep 2007
#3
Unfortunately, that approach did not work. If you do not enter root's pwd correctly, the script terminates. If you enter it correctly, then the script is run as root. And this was a problem since now you are directed to root's wallpaper directory (after all you just made yourself root). So no matter which approach I used, I had trouble getting zenity to point to the user's wallpaper directory (in the slim chooser script).

So to make a long story short, I remembered a discussion I had with the developer of nitrogen in the use of symlinks. I figured why not learn two new things: symlinks and issuing more than one command per button in a gtkdialog script? Finally, I solved the puzzle. The general routine is:

1. Choose the slim option in the control center.
2. A symlink is created to the user's wallpaper folder.
3. Ask for root's password and if correct, launch the slim background chooser.
4. If a user chooses a background, set it and output the operation was successful. Otherwise exit the script.

Although your advice didn't help directly, it helped me indirectly because instead of giving up, I strengthened my skills.

john
Posts: 1,520
eriefisher
Joined: 07 Oct 2007
#4
Motivation!
Posts: 61
thinkpada21
Joined: 13 Sep 2007
#5
Just one small issue. The file chooser is being opened with root privilege. I would recommend changing your original su command:

Code: Select all

wterm -tr +sb -fg white -T"System" -e su -c"cp -bv \"$slim_background\" /usr/share/slim/themes/antiX/background.jpg; zenity --info --text='Background Changed.\nPlease Logout/Login see changes.'"
Posts: 1,081
OU812
Joined: 29 Sep 2007
#6
Thanks for the heads up, but I did rewrite the script. If you're interested, here it is:

Code: Select all

#!/bin/sh

cd Background

slim_background=`zenity --file-selection --title="Select a Background"`

if [ $? = 0 ] ; then
  cp -bv"$slim_background" /usr/share/slim/themes/antiX/background.jpg

  zenity --info \
    --text="Background Changed.\nPlease Logout/Login to see changes."
fi
and in the control center

Code: Select all

<action>ln -s $HOME/Wallpaper/ Background &</action>
<action>wterm -tr +sb -fg white -T"Root Password Needed" -e su -c slimbackground.sh</action>
john