1.0.1 how to run sikuli script from command line

Asked by eduardobedoya

Hi
Im using Sikuli 1.0.1 installed in F drive in a windows8 64bit system.

I've been trying to run a sikuli script (scriptname.sikuli) directly from comand line without having to open sikuli-ide.jar before.
I have search on internet, but it looks like the way to do this differ depending on which version you are using
I have read this without any result:
http://doc.sikuli.org/faq/010-command-line.html?highlight=command%20line

I have try all these in command line without result

F:\APPS n DEVICES\2 MACRO RECORDERS\Sikuli\sikuli-ide.jar -r F:\APPS n DEVICES\2 MACRO RECORDERS\Sikul\scripts\lastone.sikuli

@start F:\APPS n DEVICES\2 MACRO RECORDERS\Sikuli\runIDE.cmd -r F:\APPS n DEVICES\2 MACRO RECORDERS\Sikul\scripts\lastone.sikuli

java -jar F:\APPS n DEVICES\2 MACRO RECORDERS\Sikuli\sikuli-ide.jar F:\APPS n DEVICES\2 MACRO RECORDERS\Sikul\scripts\lastone.sikuli

How can I do this?
THanks Advanced.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:

This question was reopened

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

the pathnames should not have any blanks

Revision history for this message
eduardobedoya (gonnabdh) said :
#5

Hi RainMan,
I moved the installation folder in C:\ ......
and I runned
@start C:\Sikuli\runIDE.cmd -r C:\Sikuli\scripts\lastone.sikuli
and it works,

Just notice that I placed the sikuli scripts inside the installation path, and it worked,
but if I put the sikuli scripts in another path (with blanks), it does not work, I guess scripts path also have to avoid any blank, am I right?
Also when I run the script via command line, when it ends performing the script, it lets the command line open. So I edit the runIDE.cmd adding an exit in the last line, and it worked.

What I still wondering is (hope you can help me) when running the sikuli script from command line (no mather if it was *.sikuli or *.skl script file) it took 7 sec to apply, while when running the same script from sikuli GUI itself it took 3sec, isn't there any way to run scripts from command line faster, since I would like to repeat that script several times.
Does the Sikuli 1.1 have a better perform particulary running scripts from command line???

THanks Advanced.

Revision history for this message
eduardobedoya (gonnabdh) said :
#6

despite runIDE.cmd works, it allways shows this error in the command prompt

'Files' is not recognized as an internal or external command,
operable program or batch file.
+++ running this Java
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)
'MySQL' is not recognized as an internal or external command,
operable program or batch file.
'MySQL' is not recognized as an internal or external command,
operable program or batch file.
+++ trying to start Sikuli IDE
+++ using: -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine -jar
C:\Sikuli\sikuli-ide.jar
Apr 02, 2015 12:48:42 AM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
x80000002. Windows RegCreateKeyEx(...) returned error code 5.

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

I recommend to switch to version 1.1.0, since it allows, to run scripts from inside other scripts with the advantage:
- from command line: no startup delay for the second and following script
- no need to deal with command files and their crude syntax, just script as usual

see:
http://sikulix-2014.readthedocs.org/en/latest/scripting.html#running-scripts-from-within-other-scripts-and-run-scripts-one-after-the-other

If you switch: get everything out of way (e.g. environment), that belongs to previous versions.
In your case just select option 1

It is still not recommended:
- to have blanks in any path names
- to store your own stuff in the SikuliX installation folder simply for practical reasons (having problems, you simply might delete the installation folder and start again from scratch)

... but as always: everyone has to make his own experiences

Revision history for this message
eduardobedoya (gonnabdh) said :
#8

Hi RainMan I tried to read the doc, but Im not quite sure I understand, which command line would have to use in my case????
Im reading from this link http://sikulix-2014.readthedocs.org/en/latest/faq/010-command-line.html also, it this it????
--run <sikuli-folder/file> (one or more entries seperated by space)
Thanks Advanced.

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

what version of sikuli we are talking about now?

Revision history for this message
eduardobedoya (gonnabdh) said :
#11

I solved everything about 1.0.1 only that is to slow when running scripts from command line, now Im trying with 1.1.0 since you said it could improve run times.
But I don't know how to run a script from command line in this 1.1.0 new version, which I have installed in C:\sikuli
How can I achieve that?????
I have tried.
@start C:\Sikuli\runsikulix.cmd --run C:\Sikuli\scripts\lastone.sikuli
and this
--run <C:\Sikuli\runsikulix.cmd>:scripts\lastone.sikuli
with no result.
please help.

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

before fiddling around with the start command, you should simply try the normal way:

C:\Sikuli\runsikulix.cmd -r C:\Sikuli\scripts\lastone.sikuli

alternatively you might use:
java -jar C:\Sikuli\sikulix.jar -r C:\Sikuli\scripts\lastone.sikuli

this is the one, if you want to include script running into your own batch files (no start command!)

to run more scripts in a row or with some logic, I recommend to use the new feature
http://sikulix-2014.readthedocs.org/en/latest/scripting.html#running-scripts-from-within-other-scripts-and-run-scripts-one-after-the-other

Revision history for this message
eduardobedoya (gonnabdh) said :
#13

Thanks RainMan
I tried both,
C:\Sikuli\runsikulix.cmd -r C:\Sikuli\scripts\lastone.sikuli
java -jar C:\Sikuli\sikulix.jar -r C:\Sikuli\scripts\lastone.sikuli
the former took 6 seconds
the latter took 7 seconds

when you said
"I recommend to switch to version 1.1.0, since it allows, to run scripts from inside other scripts with the advantage:
- from command line: no startup delay for the second and following script"
you meaned running the second script from within other scripts, right??

But I would like to run different scripts not withing other scripts, just as fast as possible avoiding the startup delay.
I guess in my case the fastest way to run a sikuli script is to have the sikuli.jar open and run the script from there everytime needed without closing sikuli.jar interface, so the next time the same script is needed to run, I could avoid the startup delay, right?

when you said
"if you want to include script running into your own batch files"
you mean from the sikuli.jar GUI, right? I mean add a script to run from within another script???

Thanks Advanced.

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

What ever method you use, to run one script from command line, you will always have the startup delay.

With the GUI (I always name it IDE), this delay is now completely packed into the GUI startup, so that now even the first script in the IDE runs with now delay.

You just should start to experiment with the mentioned runScript() feature, that allows to setup a workflow using all features of Sikuli and at a specific point run some script.

simple example:
# main.sikuli

while True:
    if not input("repeat?"): break
    runScript(someOtherScript)

this will run the script without delay after pressing OK, until you press Cancel.

You might use hotkey to trigger script runs or the appearance/vanish of some image …

Hope it is clear now.

Revision history for this message
eduardobedoya (gonnabdh) said :
#15

Thanks Raiman
that's it, I thought about it as a posibility before I posted
Is there a chance that I can put all my scripts inside a main script, but execute each one with a different global hotkey
By global hotkey I mean like winamp that I can be running any other application and when I hit the trigger it will run sikuli.

How can I do that?
Thanks Advanced.

Revision history for this message
RaiMan (raimund-hocke) said :
#16
Revision history for this message
eduardobedoya (gonnabdh) said :
#17

Hi RainMan, ok I read your last link, abd tried this...

def openAppleMenu(event):
    App.focus("Chrome")
    Settings.DelayAfterDrag = 0
    Settings.DelayBeforeDrop = 0
    Settings.MoveMouseDelay = 0
    hover(Pattern("1427842411231.png").similar(0.94))
    mouseDown(Button.LEFT)
    count = 0
    try:
        matches = list(findAll(Pattern("1425879837185.png").exact()))
        count = len(matches)
    except FindFailed:
        pass #nothing to do
    print "found:", count

    if count > 0:
        sortedMatches = sorted(matches, key=lambda m:m.y) # sorts top to bottom
        hover(sortedMatches[-1]) # take the last one
    mouseUp(Button.LEFT)

Env.addHotkey(Key.F2, KeyModifier.ALT+KeyModifier.CTRL, openAppleMenu)

I run this script and it shows in the Message box...
"[info] HotkeyManager: add Hotkey: CTRL+ALT F2 (113, 10)"

but it just doesn't work, whenever I prese the Alt Ctrl F2 keys nothing happen
What I am doing wrong???

THanks Advanced.

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

Yep, normal first-time-use-of-this-feature-misunderstanding:

After the
Env.addHotkey(....

the script simply ends ;-)
... and the hotkey is no longer valid of course

So you have to keep the script running somehow.

for testing just add this

while True:
    wait(1)

now the script runs forever and should react on the hotkey.

In production you should have some termination logic or just kill the script using the abort key.

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

BTW, this is exactly where you could make your whole stuff some more transparent.

# openAppleMenu.sikuli
App.focus("Chrome")
Settings.DelayAfterDrag = 0
Settings.DelayBeforeDrop = 0
Settings.MoveMouseDelay = 0
hover(Pattern("1427842411231.png").similar(0.94))
mouseDown(Button.LEFT)
count = 0
try:
    matches = list(findAll(Pattern("1425879837185.png").exact()))
    count = len(matches)
except FindFailed:
    pass #nothing to do
print "found:", count

if count > 0:
    sortedMatches = sorted(matches, key=lambda m:m.y) # sorts top to bottom
    hover(sortedMatches[-1]) # take the last one
mouseUp(Button.LEFT)

# main.sikuli
def openAppleMenu(event):
    runScript("openAppleMenu")

Env.addHotkey(Key.F2, KeyModifier.ALT+KeyModifier.CTRL, openAppleMenu)

while True;
    wait(1)

Revision history for this message
eduardobedoya (gonnabdh) said :
#24

Thanks Rainman,
pls tell me

how much processor power consume to keep the script running??
I would like to execute several browser tabs, and video stream at same time

I get it to work doing this...

def openlastone(event):
    runScript("C:\Sikuli\scripts\lastone")
Env.addHotkey(Key.F1, KeyModifier.CTRL+KeyModifier.SHIFT+KeyModifier.ALT, openlastone)

def openquestionmark(event):
    runScript("C:\Sikuli\scripts\questionmark")
Env.addHotkey(Key.F2, KeyModifier.CTRL+KeyModifier.SHIFT+KeyModifier.ALT, openquestionmark)

while True:
    wait(2)

Is something wrong with this above???

I read your suggested more transparent script above, but I don't understand something
in my humble programming understanding, the # is most used to comment something, it is so in the script you sugested above? so...
# openAppleMenu.sikuli
# main.sikuli
They are just comments right? I mean, they don't call any actual sikuli scripts? or are any kinda LABEL - GOTO commands, right?

Thanks man

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

-- I would like to execute several browser tabs, and video stream at same time
With Sikuli, you can only run one workflow at one time because of the usage of screen, mouse and keyboard.
It is the same as when you work manually: at one time you only act in one brother tab.

This has to be modelled in Sikuli the same.

-- They are just comments right?
Yes this are Python comments.
I usually use it, when I write code here, so it does not harm when copying it to the iDE.

In this case it means:
the following code is supposed to be in a script called xxx.sikuli

Revision history for this message
eduardobedoya (gonnabdh) said :
#26

Thanks RaiMan, that solved my question.

Revision history for this message
eduardobedoya (gonnabdh) said :
#29

Thanks RaiMan, that solved my question.

Revision history for this message
eduardobedoya (gonnabdh) said :
#31

Thanks RaiMan, that solved my question.