-2

This is the basic setting for hsetroot for it to work: hsetroot -center /path/to/image/ - setting the wallpaper with just that the picture. To use these options, just one has to be place within the same line of argument, using just one of these three. -flipd , -fliph , -flipv giving a total of 4 options that can be used when setting hsetroot, therefore one of the options would be "void" or not there.

Therefore in order to able to use all four options the $variable that is needed to be placed within the calling of the program has to "disappear" so that the system does not see it, with the $var still placed within the argument when it is called by the script.

A case statement is perfect for this to work. Just have RANDOM give you one of 4 numbers then the case statement picks one, or the number matches which ever case it be, then sets it into the line of argument for hestroot.

The format for that would then be, hsetroot -flipd -center /path/to/image -- to replace having to manually change that option we just use a $var then reassign that same $var within a function so that we can eliminate having to open up a terminal or script and write in again but differently. Now we can just use that variable to take the place of all four options that is given to the user to set hsetroot like this instead: hsetroot $var -center /path/to/image

where $var now becomes one of either, 1) -fliph , 2) -flipd , 3) -flipv and the 4) forth one or last option is nothing at all.

HUSTON WE NOW HAVE A PROBLEM!

As we want to eliminate having to open up that script and manually change it we have to make the system believe that the $var that is written in that line of code is no longer there. It has to disappear or turn invisible so that it does not effect the program that is looking for all of the arguments it needs to have in order for it to run without errors.

How do we do that?

in other words:

I have a case statement with 4 options one having to be "empty" to indicate that it is not even there. It goes as such: it is case '0' that I am having problems with as the $variable has to stay within the line of arguments but if RANDOM gives the variable a value of zero (0) then it needs to 'disappear' like it is not even there and still allow the program to use all the other arguments to still do what it does. I have all ready tried all of these:

setS="" and setS='' and setS="NULL" and unset -v setS

none of them work

flipS()
{
 RANGE=3
 val=$RANDOM
 let  "val %= $RANGE"

 case $val in 
    1 )
        setS="-flipd"
          echo "$setS 1"
        ;;
    2 )

        setS="-fliph"
          echo "$setS 2"
            ;;
    3 )

        setS="-flipv"
          echo "$setS  -- 3"
            ;;
    0 )

         setS=' '
           echo "$setS   -- 4"
            ;;
esac
}
 flipS 

this is for hsetroot to randomize the screen setting Syntaxis: hsetroot [command1 [arg1..]] [command2 [arg1..]]... with -flipv etc. they take no arg after it. just the placing of that in itself.

NOTE: I am using just about every argument that hsetroot has in a RANDOM fashion therefore the using the case statement like this is not an option:

 RANGE=3
 val=$RANDOM
 let  "val %= $RANGE"

   cast $val in
  1 )
   hsetroot -flipd -center /path/to/image
   ;;
  2 )
   hsetroot -flipv -center /path/to/image
    ;;
  .......
  • 1
    setS= should work no ? – Kiwy Dec 18 '13 at 15:19
  • I am just haing problems with case zero, so yes setS works just not case 0 ) – uxserx-bw Dec 18 '13 at 15:21
  • if it's the default case use *) – Kiwy Dec 18 '13 at 15:25
  • that is an illogical thought. Think about it. It has a value of 0 therefore it needs a value. default in this case is nothing being in that space withing the line of arguments therefore it HAS to disappear as if it is not even there. as Default for that argument to use hsetroot is nothing there. :D – uxserx-bw Dec 18 '13 at 15:34
  • Can you clarify what you mean by then it needs to 'disappear'? – Karlson Dec 18 '13 at 16:54
3
  1. if you want 4 cases (0,1,2,3), you need RANGE=4

  2. simplify:

    flipS() {
        local options=("" "-fliph" "-flipd" "-flipv")
        local index=$(( RANDOM % ${#options[@]} ))
        setS=${options[$index]}
    }
    
  3. if you want to use setS in such a way that the command does not see it if it's an empty string, you must not quote the variable:

    hsetroot $setS -anotheroption ...
    
  • wow cool thanks for the Simplify, and yep, them quotes got me again. lol thanks! ( I had 4 before just changed to remover that option of nothing then decised to ask -- copy paste didn't put the old number back is all – uxserx-bw Dec 18 '13 at 17:36
  • ( 0, 1 , 2 , 3 ) is four so three like an array? – uxserx-bw Dec 18 '13 at 17:43
  • brain fart -- backwards thinking dismiss it -- thanks again, it works. it was the quotes I put around the "${var}" that was my problem. – uxserx-bw Dec 18 '13 at 18:05
  • color me stupid but how does one do that? – uxserx-bw Dec 18 '13 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.