Solved [SOLVED] Randomize Background Filename Issue

Good Afternoon,

I have just ported from Linux to FreeBSD 10.0 x64. I am in the process of modifying my shell scripts.

I am not a shell scripting expert. In my user shell, I use bash. I didn't change the root shell from sh. Under linus, I used the "shuf" command which doesn't exist in FreeBSD.

One shell script I had running under cron under linux, would randomize a filename taken out of a specified directory, then my shell script would pipe it to the appropriate entry in MATE to change the background. You see, MATE doesn't have this functionality.

Here is my code-snippet(non-working as I removed the linux specific code)
Code:
#!/usr/local/bin/bash
#
# Mate 1.6 version for changing backgrounds in a cron job
#
gsettings set org.mate.background picture-filename

I need to add FreeBSD functionality to the end of that line that looks at a specified directory, and selects a filename from that directory at random.

Can someone please help me out?

Sincerely and respectfully,


Dave
 
Re: Randomize Background Filename Issue

Thank you for the post....

I do not have the knowledge to have it return one lone single filename. It randomizes the whole dir...I need something that returnes only one filename at a time, and at random.

Suggestions?


Sincerly and respectfully,


Dave
 
Re: Randomize Background Filename Issue

Just also noticed that sort(1) has an option for random order. To produce a random filename from the files in picturedir:
ls picturedir | sort -R | head 1
 
Re: Randomize Background Filename Issue

Well..............

wblock to the rescue again!


That works well and now I can complete my script changeover....

My sincerest thanks!


Dave
 
For others looking to do the same.......

Code:
#!/usr/local/bin/bash

# Mate 1.6 version

gsettings set org.mate.background picture-filename /usr/home/dcbdbis/Backgrounds/`ls /usr/home/dcbdbis/Backgrounds|sort -R|head -n1`

I am using bash as my user shell. Others shells may need slight alterations.


Sincerely and respectfully,


Dave


PS: If you want it to change periodically, then add it to a cron job at your chosen interval
 
Back
Top