How to start more than one script at boot in one sikuli-ide.sh file

Asked by malto

HI!

Autostart sikuli-ide.sh -r <sikuli-file> - started, its easy

Idea to add some options to sikuli-ide.sh that pointed to action (mean more that one script in one sikuli process)

TA!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
malto
Solved:
Last query:
Last reply:
Revision history for this message
malto (malditomalto) said :
#1

UPD: ok, just create some big script in sikuli with all options (wait time)

Revision history for this message
RaiMan (raimund-hocke) said :
#2

for this easy version all scripts have too be in one folder

--- running scripts in sequence one after the other

# ---- main.sikuli
import script1
import script2
# ....
import scriptN

# each of the above scripts contain
# ---- scriptN.sikuli
from sikuli import *
click("some-image.png")
# whatever Sikuli coding you want

and run it using
sikuli-ide.sh -r path-to-main.sikuli

--- if you want to run the scripts in parallel
The threading module contains some additional features to implement some locking between the different scripts.
Be aware that running Sikuli scripts in parallel might lead to messing mouse and key board usage up, so the scripts must fit together according this behavior (e.g. triggered by some exclusive image or via a hot-key).

# ---- main.sikuli
import threading

myThreads = []

class RunScript(threading.Thread):
    def __init__(self, script):
        threading.Thread.__init__(self)
        self.script = script
    def run(self):
        exec("import"+self.script)

def doRun(script):
    myThreads.append(RunScript(script))
    myThreads[-1].start()

# start all scripts to run in parallel
doRun("script1")
doRun("script2")
# ....
doRun("scriptN")

# wait for all scripts to terminate
for t in myThreads:
    t.join()

Both above approaches can be combined and enriched with parameter processing via sys.argv, to get the scripts to run and a loop to flexibly start the scripts.

The threaded scripts must be able to run standalone.

Hope this was your question ;-)