Absolute begginer needs help with some scripting issues...
Hi all! Perhaps someone can shed some light or point me to the right place with a few problems I'm having? I have searched google as well as this forum and the ubuntu forums as well but to no solution.
I have set up a script to run on login or by double-clicking the executable script file that would pair my ubuntu jaunty laptop to the external bluetooth mouse if a few conditions are met.
Here's the pseudo-code:
-output to screen a message to tell user to hit space/right arrow/whatever if they wish to begin
-read keyboard input within a timeout limit
-if input matches, alert user to turn on mouse
-pair the mouse
-alert user pairing has occurred
The actual code of the executable scroll.sh:
echo "Connect BT mouse?\nhit <space>" | osd_cat -p top -A centre -s 2 -f '-b&h-lucida-medium-r-normal-*-74-*-*-*-p-*-iso10646-1' -c pink
read -t 2 -n 2 keypressed
if [ "$keypressed" = 'bt' ]; then
echo "Connect mouse\npairing..." | osd_cat -p middle -A centre -s 4 -f '-b&h-lucida-medium-r-normal-*-74-*-*-*-p-*-iso10646-1' -c pink &
gksudo hciconfig hci0 reset
sudo hidd --search
echo "Successfully\npaired..." | osd_cat -p bottom -A centre -s 4 -f '-b&h-lucida-medium-r-normal-*-74-*-*-*-p-*-iso10646-1' -c cyan
echo "Aborted..." | osd_cat -p middle -A centre -s 2 -f '-b&h-lucida-medium-r-normal-*-74-*-*-*-p-*-iso10646-1' -c black
-Running from a terminal works okay, but the on-screen output writes the \n instead of skipping a line. I'd rather not use the terminal anyhow.
-Double clicking on the scroll.sh gives me a few options: <cancel, run in terminal, display, or run>; if I choose RUN, the first message pops up, but upon typing my input prompt to trigger the IF condition, NOTHING (aborted message comes up) happens. I'm not sure if it's because the scroll.sh is still highlighted, but I've tried with all other windows closed to no avail. If I run from terminal after clicking the scroll.sh, it works fine. So there seems to be a problem getting keyboard input unless in a terminal.
-If I set spacebar as the trigger input, it does not work in ANY of the above scenarios, but if I use letters such as 'bt' then it works fine in the terminal. Optionally it would be good to be able to use an F-key or arrow key...
-I'd like to be able to extend the conditions to run the program if the mouse is on but not already paired. Ie. if it's off, remind to turn on the mouse or if it's already paired, explain that it's paired. I tried using some grep commands to look for the mac address of the mouse using hcitool dev command, but it seems that it's always present whether the mouse is off or on! Is there a file/command that gives distinguished output for mouse on or off?
Any help is appreciated!