Mac: Can't access menu of application

Asked by Terence Cooper

(Investigating use of Sikuli as a test tool.) As soon as I start running the Sikuli script, the Mac gives Sikuli the focus and displays the Sikuli menu bar at the top of the Mac display - replacing the application menu bar. How can I get around this? Sorry this is a basic question - I'm new to Sikuli.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Terence Cooper
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

On Mac, you have to use App.focus() (see docs) to get the requested app back to the foreground after starting a script.

popup() and input() steel focus again. So after each usage, you have to App.focus() again.

Revision history for this message
Terence Cooper (terence-o) said :
#2

Thx for the rapid response. Actually, I had already tried App.focus(), but this causes a popup with message to the effect "app quit unexpectedly" + 3 buttons - Ignore, Report... , Reopen. In fact the app has not quit. I'm also investigating starting the app from the command line, running Sikuli in the background. Any more suggestions would be very welcome!

Revision history for this message
Terence Cooper (terence-o) said :
#3

Sorry, I meant to say 'starting Sikuli from the command line' above.

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

What Mac version?

What Sikuli version?

What is the app to be focused?

What happened, when running from command line?

Revision history for this message
Terence Cooper (terence-o) said :
#5

On Fri, Sep 30, 2011 at 1:45 AM, RaiMan <
<email address hidden>> wrote:

> Your question #172755 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/172755
>
> Status: Open => Needs information
>
> RaiMan requested more information:
> What Mac version?
>

Mac OS X 10.6.8
3.4Ghz i7, 8GB

>
> What Sikuli version?
>

Sikuli X-1.0rc3 (r905)

>
> What is the app to be focused?
>

The app to be focused is not known to 3rd parties. Its a java app. In the
dock it appears as "txdev"

>
> What happened, when running from command line?
>
When I enter the following at the command line:
 > open -g /Applications/Sikuli-IDE.app/sikuli-ide.sh
/Users/:terence.cooper/Documents/siku_1.sikuli
I get an xcode window pop up showing the contents of sikuli-ide.sh:
#!/bin/sh
DIR=`dirname $0`
cd $DIR
./Contents/MacOS/JavaApplicationStub $@

The first few lines of my Sikuli script are:

TxDev = App.focus("txdev")
if not TxDev.window():
    print "\nNO TXDEV\n"
    exit()

>
> --
> To answer this request for more information, you can either reply to
> this email or enter your reply at the following page:
> https://answers.launchpad.net/sikuli/+question/172755
>
> You received this question notification because you asked the question.
>

--
Terence Cooper
TxVia 340 Madison Ave., 3rd Floor
New York, NY 10173
<email address hidden>
www.txvia.com
Phone: 212-937-4231

Revision history for this message
Terence Cooper (terence-o) said :
#6

 > open -g -a /Applications/Sikuli-IDE.app /Users/terence.cooper/Documents/siku_1.sikuli

 - opens the ide in the background as desired but the script doesn't run.

Trying to run the script with -r (same results for --run):

 > open -g -a /Applications/Sikuli-IDE.app '-r /Users/terence.cooper/Documents/siku_1.sikuli'
open: invalid option -- r

 > open -g -a /Applications/Sikuli-IDE.app '/Users/terence.cooper/Documents/siku_1.sikuli -r'
The file /Users/terence.cooper/Documents/siku_1.sikuli -r does not exist.

 > open -g -a /Applications/Sikuli-IDE.app /Users/terence.cooper/Documents/siku_1.sikuli --args -r

pop up dialog with message: Cannot launch Java application Uncaught exception in main method:
java.lang.NullPointerException

These are just a few of the many variations I've tried! Please advise!

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

--- running a Sikuli script from command line

On Mac: If you want to run a script (the IDE stays invisible):

In Terminal:
/Applications/Sikuli-IDE.app/sikuli-ide.sh -r /Users/terence.cooper/Documents/siku_1.sikuli

an alternative leaving the IDE totally out:
java -jar /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar /Users/terence.cooper/Documents/siku_1.sikuli

Uuups: just realized: the latest version reports an error at the end "[error] Can't run this Sikuli script: ...", but the script is run perfectly. So just ignore the message - I will report a bug.

If you want to hide the Terminal session automagically, put at the beginning of your script:
switchApp("Terminal")
type("h", KeyModifier.CMD)

--- using the App class feature

on Mac, this works:
# once at beginning of script
myApp = App("your-app")
if not myApp.window(): # check: open already?
      myApp.open() # open it
      while not myApp.window(): wait(1) # wait for app window, to be ready
myApp.focus() # give focus to app, can be used later as needed

"your-app" has to be the string, that you could use for your app to open it with the open -a Terminal command.

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

BTW: to access the menu of the app (once it is in foreground), you might use:

type(Key.F2, KeyModifier.CTRL)

to access the menu and use keyboard actions to navigate through the menu.

Revision history for this message
Terence Cooper (terence-o) said :
#9

RaiMan, thanks for all the help, I'm well past these initial problems now.

Do you have any suggestions for increasing the reliability of text recognition?
And also, overall speed of execution?

Many thanks,

Terry.

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

cheers, keep on running ;-)

--- text recognition
with the current rc3(r905) this is still at the poor level of rc2.
Currently the developers are on the way, to implement improvements - but not yet released.
Have a look at the updated summary bug 710586

--- overall speed of execution
When searching the whole screen, you usually can not run more than 2-3 searches per second. The only way to speed things up is to narrow the region, where Sikuli should look for something.
Have a look at faq 1607 for more tips.