xautomation infinite loop

Hello, I’ve just gotten OpenSuSE 11.0 installed and configured almost how I want it. I switched my secondary computer over from windows and have run into a small roadblock.

I normally use a program called AutoHotKey in windows for simple scripts & macros. Through the research I’ve done, xautomation seems to be the closest thing I can get to AutoHotKey, but I’m not exactly sure how to set up a script to accomplish what I want.

An example of a script I use in AutoHotKey:


#InstallKeybdHook
#InstallMouseHook
#MaxThreadsPerHotkey 3
XButton2::
#MaxThreadsPerHotkey 1
if KeepXButton2Running
{
    KeepXButton2Running := false
    return
}
; Otherwise:
KeepXButton2Running := true
Loop
{
    Send, 2
	Sleep, 5000
    if not KeepXButton2Running
        break
}
KeepXButton2Running := false
return

Basically what this does is, when I click button 5 (defined as XButton2) on my mouse, the loop will begin processing.

In this example, I’m simply sending (simulating) the 2 key (standard 2 key, not numpad 2) being pressed (and released) every 5 seconds infinitely until I press mouse button 5 (defined as XButton2) again.

I have several other scripts & macros that I need as well, but feel if I can get this one working I’ll be fine getting everything else set up.

I’m very new to scripting in sh, perl, etc and have only come up with the following:


#!/bin/sh
while:
    xte "keydown 2" "keyup 2"
    sleep 5
done

I receive a few syntax errors (as expected since this is new for me) and don’t know how to proceed. I should note though that I think I’m on the right track, before the script dies the 2 key is being sent twice; but only twice.

Here’s the output when I run the script:


keldek:~/Documents> sh test.sh
test.sh line 3: while:: command not found
2
test.sh: line 7: syntax error near unexpected token `done'
test.sh: line 7: `done
keldek:~/Documents>2

Notice the 2 key is being sent twice, so I think (hope) I’m at least close to being on the right track lol.

Now, the script I use in autohotkey uses the input of button 5 on my mouse, to keep things simple the trigger can be a keypress instead… for instance, if I press Ctrl + F1 the loop would process until I press Ctrl + F1 again.

If this is not doable, let’s say I start the loop with Ctrl + F1, and end the loop with Ctrl + F2.

I’d even settle for no trigger key, and the loop running indefinitely until I kill the script.

Any and all help on this matter is greatly appreciated, and I’m open to all suggestions and feedback.

Thanks :slight_smile:

The carbonbased lifeform Keldek inspired opensuse.org.help.applications with:
>
…]
> In this example, I’m simply sending (simulating) the 2 key (standard 2
> key, not numpad 2) being pressed (and released) every 5 seconds
> infinitely until I press mouse button 5 (defined as XButton2) again.
>
> I have several other scripts & macros that I need as well, but feel if
> I can get this one working I’ll be fine getting everything else set up.
>
> I’m very new to scripting in sh, perl, etc and have only come up with
> the following:
>
> Code:
> --------------------
>
> #!/bin/sh
> while:
> xte “keydown 2” “keyup 2”
> sleep 5
> done
>
> --------------------
>
>
> I receive a few syntax errors (as expected since this is new for me)

Assuming you’re using the Bash shell; try using ‘help <token>’ to find
out what syntax is expected.
So for ‘while’ that would get you:
$help while
while: while COMMANDS; do COMMANDS; done
Expand and execute COMMANDS as long as the final command in the
`while’ COMMANDS has an exit status of zero.

Here’s the output when I run the script:

Code:

keldek:~/Documents> sh test.sh
test.sh line 3: while:: command not found

That explains why this error comes up, you didn’t give ‘while’ a test command
to perform.
For an infinite loop, ‘while’ needs to run a command that never returns
a ‘1’ status, e.g. ’ 1 ]’.
This tests if ‘1’ is true (which it is), and in Bash True returns 0, so
the while loop repeats.

2
test.sh: line 7: syntax error near unexpected token done' &gt; test.sh: line 7: done

And this is because you neglected to use the ‘do’ token after the test
command.

So, the code should have been:

while 1 ];do
xte “keydown 2” “keyup 2”
sleep 5
done

> Now, the script I use in autohotkey uses the input of button 5 on my
> mouse, to keep things simple the trigger can be a keypress instead…
> for instance, if I press Ctrl + F1 the loop would process until I press
> Ctrl + F1 again.

You can achieve this with xmodmap(1) or, easier, an ‘on/off’ script that
is called by a icon in the panel or on the desktop.

Theo

theo at van-werkhoven.nl ICQ:277217131 SuSE Linux
linuxcounter.org: 99872 Jabber:muadib at jabber.xs4all.nl AMD XP3000+ 1024MB
“ik heb niets tegen Microsoft, ik heb iets tegen
de uitwassen van Microsoft”