Package org.sikuli.script
Class App
- java.lang.Object
-
- org.sikuli.script.App
-
public class App extends java.lang.ObjectApp 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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classApp.Type
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringlastRunResultstatic intlastRunReturnCodestatic java.lang.StringlastRunStderrstatic java.lang.StringlastRunStdout
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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(java.lang.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(java.lang.String title)tries to identify a running app with name or (part of) window title bringing its topmost window to frontstatic Appfocus(java.lang.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 java.util.List<App>getApps()static java.util.List<App>getApps(java.lang.String name)static java.lang.StringgetClipboard()evaluates the current textual content of the system clipboardjava.lang.StringgetExec()java.lang.StringgetName()java.lang.StringgetNameGiven()java.lang.StringgetOptions()intgetPID()java.lang.StringgetTitle()java.lang.StringgetTitle(int windowNumber)java.lang.StringgetToken()java.util.List<Region>getWindows()java.lang.StringgetWindowTitle()java.lang.StringgetWorkDir()booleanhasFocus()booleanhasWindow()booleanisClosing()booleanisRunning()booleanisRunning(int maxTime)booleanisValid()booleanisWindow()static voidlistApps()static voidlistApps(java.lang.String name)static voidlog(java.lang.String msg, java.lang.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(java.lang.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(java.lang.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(java.lang.String url)static voidpause(float time)static voidpause(int time)voidreset()static intrun(java.lang.String cmd)the given text is parsed into a String[] suitable for issuing a Runtime.getRuntime().exec(args).static voidsetClipboard(java.lang.String text)sets the current textual content of the system clipboard to the given textvoidsetExec(java.lang.String exec)voidsetFocused(boolean state)voidsetName(java.lang.String name)voidsetNameGiven(java.lang.String nameGiven)voidsetPID(int appPID)voidsetPID(java.lang.String appPID)voidsetToken(java.lang.String appToken)AppsetUsing(java.lang.String options)voidsetWindow(java.lang.String appWindow)booleansetWorkDir()booleansetWorkDir(java.lang.String workDirPath)static Regionstart(App.Type appType)java.lang.StringtoString()java.lang.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.
-
-
-
Method Detail
-
isWindow
public boolean isWindow()
-
waitForWindow
public Region waitForWindow()
-
waitForWindow
public Region waitForWindow(int seconds)
-
openLink
public static boolean openLink(java.lang.String url)
-
pause
public static void pause(int time)
-
pause
public static void pause(float time)
-
log
public static void log(java.lang.String msg, java.lang.Object... args)
-
logOn
public static void logOn()
-
logOff
public static void logOff()
-
reset
public void reset()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toStringShort
public java.lang.String toStringShort()
-
getApps
public static java.util.List<App> getApps()
-
getApps
public static java.util.List<App> getApps(java.lang.String name)
-
listApps
public static void listApps()
-
listApps
public static void listApps(java.lang.String name)
-
getToken
public java.lang.String getToken()
-
setToken
public void setToken(java.lang.String appToken)
-
setUsing
public App setUsing(java.lang.String options)
-
setNameGiven
public void setNameGiven(java.lang.String nameGiven)
-
getNameGiven
public java.lang.String getNameGiven()
-
getOptions
public java.lang.String getOptions()
-
getName
public java.lang.String getName()
-
setName
public void setName(java.lang.String name)
-
getExec
public java.lang.String getExec()
-
setExec
public void setExec(java.lang.String exec)
-
getTitle
public java.lang.String getTitle()
-
getTitle
public java.lang.String getTitle(int windowNumber)
-
getWindowTitle
public java.lang.String getWindowTitle()
-
setWindow
public void setWindow(java.lang.String appWindow)
-
setPID
public void setPID(int appPID)
-
setPID
public void setPID(java.lang.String appPID)
-
getPID
public int getPID()
-
setWorkDir
public boolean setWorkDir()
-
setWorkDir
public boolean setWorkDir(java.lang.String workDirPath)
-
getWorkDir
public java.lang.String getWorkDir()
-
isValid
public boolean isValid()
-
isRunning
public boolean isRunning()
-
isRunning
public boolean isRunning(int maxTime)
-
hasWindow
public boolean hasWindow()
-
open
public static App open(java.lang.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 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
public static App open(java.lang.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 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
public static boolean close(java.lang.String appName)
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
public static App focus(java.lang.String title)
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
public static App focus(java.lang.String title, int index)
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
public Region 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
public Region window(int winNum)
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
public static 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
public java.util.List<Region> getWindows()
-
run
public static int run(java.lang.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 returncode- Parameters:
cmd- the command to run starting with an executable item- Returns:
- the final returncode of the command execution
-
getClipboard
public static java.lang.String getClipboard()
evaluates the current textual content of the system clipboard- Returns:
- the textual content or empty string if not possible
-
setClipboard
public static void setClipboard(java.lang.String text)
sets the current textual content of the system clipboard to the given text- Parameters:
text- text
-
-