[1.1.1] macOS: App.focus: Occasionally: Where is osascript

Asked by Jeff_Vallis

Occasionally !!
My Log File :-
[log] App.focus: [0:TynonS2]

My Screen (Pity I cant load a screen shot)
Will have a box on the screen
headed Choose Application
sub heading Where is osascipt
and a list of all applications from my application directory

Whilst this is happening the Application TynonS2 is loaded by the App.focus command
The Script will then wait until the Cancel is clicked on the Choose Application box

As Sikuli is paused I have no way to deal with this box within the Script

Any Suggestions would be welcome

as I said - Occasionally !! - maybe once in 500 times

Question information

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

Thanks for the pointer.

I know this problem, but did not find a solution yet.

In version 2 I will revise this section anyways and possibly be able to fix it in 1.1.x then.

Revision history for this message
Jeff_Vallis (vallis-pj) said :
#2

It so Occasional that its not a major problem
Have wriitten an Automator Script to Run Prior to the Script opening and closing the App but guess I will only find out if it "FAILS" to solve the problem, if the box appears again sometime in the future

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

Good workaround ;-)

Just "forget" the problem - I have it on the list now ;-)

Revision history for this message
Jeff_Vallis (vallis-pj) said :
#4

Information
Automator Script Opened the App Closed it - not quit so sat in Dock - this did not resolve the issue

Revision history for this message
Jeff_Vallis (vallis-pj) said :
#5

More Information
I added some debug code to the script and the app.focus failed at the same time that GoogleSoftwareUpdateDaemon was running according to Console

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

ok, thanks.

I decided, that we have to live with it, until I have a better solution in version 2 later this year.

Revision history for this message
Jeff_Vallis (vallis-pj) said :
#7

Can you help me code a workaround,have tried to understand http://sikulix-2014.readthedocs.io/en/latest/region.html#observing-visual-events-in-a-region but its beyoind my skill set.

What I want to do is :-
replace App.focus("Tynon") and use App_Focus_Failing() in the following :-

def If_Choose_App_Appeared():
    setRect(458, 187, 823, 657)
    while exists(Pattern("1490794202722.png").similar(0.90)): # Image with Choose Application Header
        print "Running Check_App_Focus - Found Choose Application"
        if exists("1490794220568.png"): # Cancel Button
            print "Check_App_Focus - Found Cancel"
            click(getLastMatch())

def App_Focus_Failing():
    # I want to set If_Choose_App_Appeared() to be running in background
    App.focus("Tynon")
    # I want to Stop If_Choose_App_Appeared() to be running in background

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

ok, this is much easier:

def If_Choose_App_Appeared():
    shitHappened = false
    setRect(458, 187, 823, 657)
    while exists(Pattern("1490794202722.png").similar(0.90)): # Image with Choose Application Header
        print "Running Check_App_Focus - Found Choose Application"
        if exists("1490794220568.png"): # Cancel Button
            print "Check_App_Focus - Found Cancel"
            click(getLastMatch())
            shitHappened = true
    return shitHappened

def App_Focus_Failing():
    max = 3
    while True:
        App.focus("Tynon")
        if not If_Choose_App_Appeared():
            break # focus should have worked, otherwise try again
        max -= 1
        if max < 0: # to avoid endless loop if workaround does not work
            print "no chance - exiting"
            exit(1)

Revision history for this message
Jeff_Vallis (vallis-pj) said :
#9

Tried the above code as soon as recieved and have been waiting for the choose Choose Application box to appear - checking my log each day to see if print "Running Check_App_Focus - Found Choose Application" had appeared.
Today the box was on the screen and again the process hang (waited) for cancel to be clicked manually.
So it does not get to the line :-
 if not If_Choose_App_Appeared():
until box is clicked.

From
http://sikulix-2014.readthedocs.io/en/latest/region.html#observing-visual-events-in-a-region
would observeInBackground do what I am trying to achieve
if so how would I code it switching it on before App.focsu and switching it off after

do something to observeInBackground
App.focus("Tynon")
do something to stopObserver()

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

switching to observe would not change anything.

As I understand the code:
if "Running Check_App_Focus ..." is printed, then the logic found the offending dialog.
Then the cancel button should be found and "Check_App_Focus ..." should be printed and the cancel button should be clicked.

if only the first message is printed and not the second one, then the cancel button is not found.

So check your image. You should have a screen shot of the situation when the box is there but cancel is not clicked.

Revision history for this message
Jeff_Vallis (vallis-pj) said :
#11

Today the box was on the screen and again the process hang (waited) for cancel to be clicked manually.
And

"Running Check_App_Focus - Found Choose Application" Did Not Appear

so it hangs at :-
 App.focus("Tynon")

and does not get to :-
        if not If_Choose_App_Appeared():

So from your comments it looks like it impossible to get round this within one Sikuli Script
I am going to try running 2 scripts at the same time
1.Normal Script which includes the App.focus
2.Second Script - executed from command line to run in background the :-
def If_Choose_App_Appeared():

Second script will check text file and close if told from text file.
Sounds Dangerous but could be fun and will keep me occupied tomorrow

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

LOL .... and sorry - so stupid: the dialog box is triggered from within the App.focus() handling - so it cannot proceed until clicked and hence cannot come to the code, that would click the box from within the script.

So correct: either the App.focus() or the box handling must run in parallel.

- App.focus(): just put it in def() and run the def() in a Python thread (simple)

- box handling: use observe in background with the code in an onAppear() handler.

I do not have the time currently for example code. Come back again if you need more help.

Revision history for this message
Jeff_Vallis (vallis-pj) said :
#13

This is what I have done after Finding some code using Python Thread : not that I understand the Syntax of the call
Handling the Box problem - I have added to my coding for Blocked Screen which has many checks -like Flash Crashing any lots of others that I have encountered in the last 2 years - Thanx for your assistance

Posted in case anyone searches for App.focus

def Thread_App_Focus_Failing(v_Sub_Open_Which_App): # This will be Threaded
    App.focus(v_Sub_Open_Which_App)

def App_Focus_Failing():
    global Sub_Open_Which_App
    import thread
    thread.start_new_thread(Thread_App_Focus_Failing, (Sub_Open_Which_App, ))

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

well done :-))