Package org.sikuli.script
Class App
java.lang.Object
org.sikuli.script.App
public class App extends Object
App implements features to manage (open, switch to, close) applications. on the system we are running on and to
access their assets like windows
TAKE CARE: function behavior differs depending on the running system (cosult the docs for more info)
TAKE CARE: function behavior differs depending on the running system (cosult the docs for more info)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classApp.Type -
Field Summary
Fields Modifier and Type Field Description static StringlastRunResultstatic intlastRunReturnCodestatic StringlastRunStderrstatic StringlastRunStdout -
Constructor Summary
-
Method Summary
Modifier and Type Method Description booleanclose()tries to close the app defined by this App instance, waits max 10 seconds for the app to no longer be runningbooleanclose(int waitTime)tries to close the app defined by this App instance, waits max given seconds for the app to no longer be runningstatic booleanclose(String appName)tries to identify a running app with the given name and then tries to close itintcloseByKey()intcloseByKey(int waitTime)booleanfocus()tries to make it the foreground application bringing its frontmost window to frontstatic Appfocus(String title)tries to identify a running app with name or (part of) window title bringing its topmost window to frontstatic Appfocus(String title, int index)tries to identify a running app with name or (part of) window title bringing its window with given index to frontstatic RegionfocusedWindow()evaluates the region currently occupied by the systemwide frontmost window (usually the one that has focus for mouse and keyboard actions)static List<App>getApps()static List<App>getApps(String name)static StringgetClipboard()evaluates the current textual content of the system clipboardStringgetExec()StringgetName()StringgetNameGiven()StringgetOptions()intgetPID()StringgetTitle()StringgetTitle(int windowNumber)StringgetToken()List<Region>getWindows()StringgetWindowTitle()StringgetWorkDir()booleanhasFocus()booleanhasWindow()booleanisClosing()booleanisRunning()booleanisRunning(int maxTime)booleanisValid()booleanisWindow()static voidlistApps()static voidlistApps(String name)static voidlog(String msg, Object... args)static voidlogOff()static voidlogOn()booleanopen()tries to open the app defined by this App instance
do not wait for the app to get runningbooleanopen(int waitTime)tries to open the app defined by this App instance
and waits until app is runningstatic Appopen(String appName)tries to open an app using the given name and waits 1 sec for being ready If the app is already open, it is brought to foregroundstatic Appopen(String appName, int waitTime)tries to open an app using the given name and waits waitTime for being ready If the app is already open, it is brought to foregroundstatic booleanopenLink(String url)static voidpause(float time)static voidpause(int time)voidreset()static intrun(String cmd)the given text is parsed into a String[] suitable for issuing a Runtime.getRuntime().exec(args). quoting is preserved/obeyed. the first item must be an executable valid for the running system.
After completion, the following information is available:
App.lastRunResult: a string containing the complete result according to the docs of the run() command
App.lastRunStdout: a string containing only the output lines that went to stdout
App.lastRunStderr: a string containing only the output lines that went to stderr
App.lastRunReturnCode: the value, that is returnd as returncodestatic voidsetClipboard(String text)sets the current textual content of the system clipboard to the given textvoidsetExec(String exec)voidsetFocused(boolean state)voidsetName(String name)voidsetNameGiven(String nameGiven)voidsetPID(int appPID)voidsetPID(String appPID)voidsetToken(String appToken)AppsetUsing(String options)voidsetWindow(String appWindow)booleansetWorkDir()booleansetWorkDir(String workDirPath)static Regionstart(App.Type appType)StringtoString()StringtoStringShort()RegionwaitForWindow()RegionwaitForWindow(int seconds)Regionwindow()evaluates the region currently occupied by the topmost window of this App instance.Regionwindow(int winNum)evaluates the region currently occupied by the window with the given number of this App instance.
-
Field Details
-
lastRunReturnCode
public static int lastRunReturnCode -
lastRunStdout
-
lastRunStderr
-
lastRunResult
-
-
Constructor Details
-
Method Details
-
isWindow
public boolean isWindow() -
start
-
waitForWindow
-
waitForWindow
-
openLink
-
pause
public static void pause(int time) -
pause
public static void pause(float time) -
log
-
logOn
public static void logOn() -
logOff
public static void logOff() -
reset
public void reset() -
toString
-
toStringShort
-
getApps
-
getApps
-
listApps
public static void listApps() -
listApps
-
getToken
-
setToken
-
setUsing
-
setNameGiven
-
getNameGiven
-
getOptions
-
getName
-
setName
-
getExec
-
setExec
-
getTitle
-
getTitle
-
getWindowTitle
-
setWindow
-
setPID
public void setPID(int appPID) -
setPID
-
getPID
public int getPID() -
setWorkDir
public boolean setWorkDir() -
setWorkDir
-
getWorkDir
-
isValid
public boolean isValid() -
isRunning
public boolean isRunning() -
isRunning
public boolean isRunning(int maxTime) -
hasWindow
public boolean hasWindow() -
open
tries to open an app using the given name and waits waitTime for being ready If the app is already open, it is brought to foreground- Parameters:
appName- name - something that could be used on commandline to start the appwaitTime- to wait for app to open (secs)- Returns:
- the App instance
-
open
tries to open an app using the given name and waits 1 sec for being ready If the app is already open, it is brought to foreground- Parameters:
appName- name - something that could be used on commandline to start the app- Returns:
- the App instance
-
open
public boolean open()tries to open the app defined by this App instance
do not wait for the app to get running- Returns:
- this or null on failure
-
open
public boolean open(int waitTime)tries to open the app defined by this App instance
and waits until app is running- Parameters:
waitTime- max waittime until running- Returns:
- this or null on failure
-
close
tries to identify a running app with the given name and then tries to close it- Parameters:
appName- name- Returns:
- 0 for success -1 otherwise
-
isClosing
public boolean isClosing() -
close
public boolean close()tries to close the app defined by this App instance, waits max 10 seconds for the app to no longer be running- Returns:
- this or null on failure
-
close
public boolean close(int waitTime)tries to close the app defined by this App instance, waits max given seconds for the app to no longer be running- Parameters:
waitTime- to wait for app to close (secs)- Returns:
- this or null on failure
-
closeByKey
public int closeByKey() -
closeByKey
public int closeByKey(int waitTime) -
setFocused
public void setFocused(boolean state) -
hasFocus
public boolean hasFocus() -
focus
tries to identify a running app with name or (part of) window title bringing its topmost window to front- Parameters:
title- name- Returns:
- an App instance - is invalid and not useable if not found as running
-
focus
tries to identify a running app with name or (part of) window title bringing its window with given index to front- Parameters:
index- of the window among the found windowstitle- name- Returns:
- an App instance - is invalid and not useable if not found as running
-
focus
public boolean focus()tries to make it the foreground application bringing its frontmost window to front- Returns:
- the App instance
-
window
evaluates the region currently occupied by the topmost window of this App instance. The region might not be fully visible, not visible at all or invalid with respect to the current monitor configuration (outside any screen)- Returns:
- the region
-
window
evaluates the region currently occupied by the window with the given number of this App instance. The region might not be fully visible, not visible at all or invalid with respect to the current monitor configuration (outside any screen)- Parameters:
winNum- window- Returns:
- the region
-
focusedWindow
evaluates the region currently occupied by the systemwide frontmost window (usually the one that has focus for mouse and keyboard actions)- Returns:
- the region
-
getWindows
-
run
the given text is parsed into a String[] suitable for issuing a Runtime.getRuntime().exec(args). quoting is preserved/obeyed. the first item must be an executable valid for the running system.
After completion, the following information is available:
App.lastRunResult: a string containing the complete result according to the docs of the run() command
App.lastRunStdout: a string containing only the output lines that went to stdout
App.lastRunStderr: a string containing only the output lines that went to stderr
App.lastRunReturnCode: the value, that is returnd as returncode- Parameters:
cmd- the command to run starting with an executable item- Returns:
- the final returncode of the command execution
-
getClipboard
evaluates the current textual content of the system clipboard- Returns:
- the textual content or empty string if not possible
-
setClipboard
sets the current textual content of the system clipboard to the given text- Parameters:
text- text
-