Can I use Sikuli to get a window title?

Asked by Parn Yin

Hello, in my script, I want to check a specified window is opened or not.
Unfortunately, there would be several applications opening and their titles may be very similar.
Like:
Application 1's title: (variable user name) - Purkinje|Dossier - Dashboard
Application 2's title: (variable user name) - Purkinje|Dossier
Application 3's title: Purkinje|Dossier Registration

So it's not able to distinguish them by using screenshots, especially the Application 2.

I know:

switchApp(application)
Switch to the specified application.
Parameters: application – the name of an application (case-insensitive) or (part of) a window title (Windows/Linux).

I am wondering that can I use Sikuli to get a specified application's window title and print it out?
For example, if there is a notepad opened and its window title is "Untitled - Notepad", can I get it by using something switchApp(application) used?

I also noticed https://answers.launchpad.net/sikuli/+question/204514 but Region.text() is still in an experimental state.

Something using CPython can do that.
However, I don't want to install too many things so that I don't want to use CPython.

Excuse me, is there a way to use Sikuli to get a window title please?
Thank you.

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:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Sorry, currently not a feature.

The only trick you can do is to try to switch through the window title candidates and check, wether the frontmost window is the one you expect, by checking some distinctive visual content.

App.focus("Purkinje|Dossier - Dashboard")
if App.focusedWindow().exists("some distinctive image.png")
    print "this is my window"
elif ....

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

is a request bug now

Revision history for this message
Parn Yin (pyin) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Liam Deacon (liam-m-deacon) said :
#4

Hi - I've found a workaround with a subprocess call to xdotool. Try the following Jython code:

import subprocess

def getActiveWindowName():
    return subprocess.Popen(['xdotool', 'getWindowfocus', 'getwindowname'],
                                                      stdout=subprocess.PIPE,
                                                      stderr=subprocess.PIPE).communicate()

Works for me on Red Hat Linux...