Results 1 to 4 of 4
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 07-27-2009 #1
- Join Date
- Jul 2009
Absolute begginer needs help with some scripting issues...
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:
#!/bin/bash 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 else echo "Aborted..." | osd_cat -p middle -A centre -s 2 -f '-b&h-lucida-medium-r-normal-*-74-*-*-*-p-*-iso10646-1' -c black exit fi exit
-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!
- 07-27-2009 #2
- Join Date
- Jan 2007
issue 1: try "echo -e"the sun is new every day (heraclitus)
- 07-27-2009 #3
So I've never used osd_cat before, but I can talk about your read issue.
What "read" does is read the pseudoterminal to which the program is connected. In your case, because you are running the script in the background, you have no way to access that pseudoterminal, therefore no input will be received by the program.
Although what you are attempting to do might be somehow possible through Bash scripting, it will involve lots of weirdness. For that reason, I would advise one of the following:
1) Run the script in a terminal and use "read" the way it expects to be used. Don't bother with osd_cat at all.
2) If it must be graphical, rewrite your program as a GUI program in C, C++, Java, etc. This way, you will be able to detect button presses easily, and you can therefore check for space or an F key as you desire.
- 07-28-2009 #4
- Join Date
- Jul 2009
Oh wow! You guys rock!
Seriously, thanks and that was fast too!
TPL, problem solved as you suggested!
Cabhan, thanks for saving me numerous hours trying to do the impossible! I will try to find another way. Part of this is about learning for me, so I will keep looking. Terminal solution is working for now though.
Thanks again! I'm glad I joined this forum.