View Single Post
Posts: 436 | Thanked: 406 times | Joined on Jan 2010
#359
Originally Posted by michaelxy View Post
I found this shell script which is running well in the shell. But I dont know the working syntax for the Desktop Command Execution Widget.

random.sh:
Code:
#/bin/sh

# randomquote - Given a one-line-per-entry datafile, this
# script randomly picks one line and displays it. Best used

awkscript="randomquote.awk.$$"

if [ $# -ne 1 ] ; then
  echo "Usage: randomquote datafilename" >&2
  exit 1
elif [ ! -r "$1" ] ; then
  echo "Error: quote file $1 is missing or not readable" >&2
  exit 1
fi

trap "/bin/rm -f $awkscript" 0

cat << "EOF" > $awkscript
BEGIN { srand() }
      { s[NR] = $0 }
END { print s[randint(NR)] }

function randint(n) { return int (n * rand() ) + 1 }
EOF

awk -f $awkscript < "$1"

exit 0
With "random.sh textfile.txt" it writes one line to the shell.

But how can I get this working in Desktop Command Execution Widget ?

Thanks
Desktop command widget is sorta buggy when it comes to these commands but what you can do is this:

Firstly when you are making this desktop execution widget make sure you only have "update when click" selected, otherwise you would be in a whole heap of probs...

Add this command:

cd /pathname && sh ScriptName.sh

where "pathname" is the location of your script and "ScriptName.sh" is the name of the script you want to run...e.g

cd /home/user/MyDocs/Scripts && sh HelloWorld.sh

... Name the widget what ever you like, and voila.